Laravel 9 – Attempt to read property "nom_prenoms" on null

Advertisements I have two models as follows. Tier Model: public function contact(){ return $this->belongsTo(ContactAdresse::class,"contact_adresse_id"); } ContactAdresse Model: public function tiers(){ return $this->hasMany(Tier::class); } Now I’m trying to retrieve the Tier associated with the Contact using this code: {{ $ContactAdresse->tier->nom_prenoms}} I have the following error. Attempt to read property "nom_prenoms" on null Does anyone have an… Read More Laravel 9 – Attempt to read property "nom_prenoms" on null

Laravel DB table – binding related information. Is there a better way here?

Advertisements I have tables "Seminars", "Users" and "UserSeminarAttendance". Users can sign up for a seminar. They can take multiple tickets (think user + child + another parent etc). The "UserSeminarAttendance" table stores the seminar ID, user ID who made the purchase, + number of tickets the user wants. I want to know how many tickets… Read More Laravel DB table – binding related information. Is there a better way here?

Issue with Eloquent: Retrieving Entries Based on Multiple Conditions

Advertisements I’m facing an issue while trying to retrieve entries using Eloquent that meet specific criteria involving filtering on two related models. The goal is to first select reservations with a "Checked-In" status and then further filter these reservations to only include those with associated receipts in the "UNPAID" status. However, I’m encountering unexpected behavior… Read More Issue with Eloquent: Retrieving Entries Based on Multiple Conditions

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

Advertisements 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… Read More Getting field value from another table returns a json collection in Laravel

Laravel many to many and hasMany, N+1

Advertisements 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… Read More Laravel many to many and hasMany, N+1

How to pass all categories and subcategories to layout laravel 9

Advertisements 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>… 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?

Advertisements 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… 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

Advertisements 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… Read More Laravel Many To Many Get element that I dont have a relationship with