Questions tagged [route-model-binding]

24 questions
6
votes
4 answers

Laravel BelongsTo Through relationship

How to implement BelongsToThrough Relationship in Laravel? I have Table: **projects_table** id **categories_table** id project_id **properties_table** id category_id Category BelongsTo Project public function project(){ return…
3
votes
5 answers

How to change Route Model Binding finding data from id to slug

I have a route like the following. Route::get('/articles/{articleSlug}' , [App\Http\Controllers\ArticleController::class, 'single']); And the method of single() at ArticleController class goes here: public function single($slug) { $article…
Pouya
  • 114
  • 1
  • 8
  • 36
2
votes
2 answers

Laravel Route Model Binding Reusability

I'm creating a like feature for my application where users can like posts, events, products etc. I have a LikeController and a Trait which handles the like functionality public function store(Post $post) { $post->like(); return…
Danny Younes
  • 579
  • 1
  • 6
  • 19
2
votes
1 answer

Laravel won't resolve model

I'm building an application to track expenses, using laravel 5.8 as the back-end. When I try to access the show method on my controller, I find laravel is giving me a fresh instance of the model instead of fetching the one matching the id…
KeepoN
  • 137
  • 1
  • 11
1
vote
0 answers

Laravel Route model binding throws NotFoundHttpException instead of ModelNotFoundException

I am using route model binding for my API routes. Route::middleware('client')->group(function(){ Route::get('/documents/{document}', [DocumentController::class, 'get']); Route::apiResource('documents',…
Vüsal Hüseynli
  • 889
  • 1
  • 4
  • 16
1
vote
1 answer

Update and Edit on Resource Controller: Can't Find Query Results for Model

I have a resource controller in my Laravel app, where all resource functions are placed. So far I have the creation and store functions working fine, but it falls on edit() and update(). As far as I can see, the issue is that it's not grabbing the…
1
vote
1 answer

Laravel 8 route model binding not return ant record?

I am using below code for route model binding but the binding variable does not return any value. MY ROUTE Route::resource('offertypes', 'OfferTYpeController'); CONTROLLER CODE public function edit(OfferType $offerType) { …
1
vote
2 answers

Route Model Binding Problem Does Not Seem To Be Working

I'm working with Laravel 8 and I have made a table like this at Blade:
memite7760
  • 69
  • 9
1
vote
0 answers

Route Model Binding returns just one record in Laravel

I have a table (post) in my database with (id, title, post) columns. I have 3 records with the same title in my table but, it returns just the first record. How to return all records with the same title using Route Model Binding? This is my…
1
vote
2 answers

Laravel 7 Route Model Binding is not working (Model in the route is always null)

I am working on a Laravel 7 project. In my project, I am doing the route model binding. But it is not working and the model in the route is always returning null. This is what I have done so far. I declare a…
Wai Yan Hein
  • 13,651
  • 35
  • 180
  • 372
1
vote
1 answer

Laravel Route Model Binding conflict when using the same structure with different models

I'm trying to create a route model binding for two models: "User" and "Article" Route::get('/{user}', 'UsersController@show'); Route::get('/{article}', 'ArticlesController@show'); Problem is, one of these will always take precedence over the other,…
gjerm94
  • 13
  • 3
1
vote
2 answers

How get lot of params from url but without (&)?

For now in Laravel i am testing url and in route i have Route::group(['prefix' => 'game'], function (){ Route::get('/location/{location?}/action/{action?}/screen/{screen?}','GameController@index')->name('game.index'); }); In controller when i…
Wraith
  • 504
  • 6
  • 28
1
vote
2 answers

Route model binding in controller@index?

I want to set up a route that fetches all Contacts associated with a Customer. The endpoint would look like /customers/{customer}/contacts such that {customer} provides context for which contacts should be returned. My routes/web.php looks like…
Erich
  • 2,408
  • 18
  • 40
0
votes
2 answers

how to solve 404 error message in laravel 8

i got error 404 while applying route model binding , i am confused where i went wrong, even though i checked route and controller are correct this is my index coding ```

product categories

0
votes
0 answers

Custom route model binding for each controller action

I am at the completion stage of my Laravel project. I am refactoring my code and query to the database, so I came to this question. Schema migration for Post model: Schema::create('posts', function (Blueprint $table) { $table->id(); …
JS TECH
  • 1,556
  • 2
  • 11
  • 27
1
2
Username Email