Getting field value from another table returns a json collection in Laravel

I am using Laravel orchid package and in layout file, I have this function: protected function columns(): iterable { $org = ”; $employeeDetails = ”; return [ TD::make(‘Userid’, __(‘User Id’)) ->cantHide() ->sort() ->filter(Input::make()), TD::make($employeeDetails, __(‘Employee Name’)) ->filter(Input::make()) ->render(function(DailyAttendance $attendance) { $employeeDetails = Employee::where(’employeeCode’, $attendance->Userid)->first([’employeeName’]); return $employeeDetails; }) ->sort(), ]; } The result is not picking… Read More Getting field value from another table returns a json collection in Laravel

Laravel many to many and hasMany, N+1

I got a model Event that has many private classes public function privateclasses() { return $this->hasMany(Privateclass::class); } This is working perfect Model Privateclass and User is connected in table "privateclass_user" with foreign key "privateclass_id" and "user_id". In model Privateclass.php: public function users() { return $this->belongsToMany(User::class); } This is also working, but when I get the… Read More Laravel many to many and hasMany, N+1

How to pass all categories and subcategories to layout laravel 9

I’m new to development, I ran into a problem, I can’t display all subcategories in the "layout.app" For each category, only one subcategory is displayed, and I need to get all subcategories in file AppServiceProvider.php public function boot() { view()->composer(‘layout.app’, function ($view){ $view->with(‘categories’, Category::with(‘subcategories’)->get()); }); } in layout.app <ul class="sub-category"> @foreach($categories as $category) <li> <a… Read More How to pass all categories and subcategories to layout laravel 9

How to do laravel eloquent table with joins, orwhere and pagination correctly?

This is my original code where i display all data for team users. $data = Teamuser::join(‘teams’, ‘teams.id’, ‘=’, ‘team_user.team_id’) ->join(‘users’, ‘users.id’, ‘=’, ‘team_user.user_id’) ->get([‘users.name as username’,’teams.name’,’users.email’,’team_user.role’,’team_user.id’,’team_user.user_id’,’team_user.team_id’]); However, since im developing a search function for the table. I try adding orwhere to the function. $data = Teamuser::join(‘teams’, ‘teams.id’, ‘=’, ‘team_user.team_id’) ->join(‘users’, ‘users.id’, ‘=’, ‘team_user.user_id’) ->get([‘users.name as… Read More How to do laravel eloquent table with joins, orwhere and pagination correctly?

Laravel Many To Many Get element that I dont have a relationship with

In laravel Many to Many relationship like the one in the Laravel Documentation example. https://laravel.com/docs/9.x/eloquent-relationships#many-to-many users id – integer name – string roles id – integer name – string role_user user_id – integer role_id – integer In the Users model I have public function roles() { return $this->belongsToMany(Role::class); } In the Roles model I have… Read More Laravel Many To Many Get element that I dont have a relationship with

How to delete a user in Laravel (eloquent) without its relations?

I have a laravel application and I want to delete the user record form users table but keep the data related to them like articles. I have this function for article public function userArticles() { return $this->hasMany(‘Application\Model\userArticles’); } I want to delete the user without deleting the articles from database, but when I do $user->delete()… Read More How to delete a user in Laravel (eloquent) without its relations?

How to get subcategory status and category status on Blade view?

$categories = Category::with(‘subcategory’)->where(‘status’,1)->take(7)->get(); view()->share(‘categories’, $categories); model Category: protected $fillable =[ ‘category_en’, ‘category_np’, ‘status’, ]; public function posts() { return $this->hasMany(Post::class); } public function subcategory() { return $this->hasMany(Subcategory::class); // category_id } } Model Subcategory: protected $fillable = [ ‘subcategory_en’, ‘status’, ‘category_id’, ‘subcategory_np’, ]; public function category() { return $this->belongsTo(Category::class); } My blade view: @foreach ($categories as… Read More How to get subcategory status and category status on Blade view?