"message": "No query results for model [App\\Venue] stats", When I run my URL using GET: moveme.test/venues/1152522/tagin/stats in postman, I get the following message:
"message": "No query results for model [App\Venue] stats",
Here is my method, nothing gets output to the screen
public function venueTaginstats($id) {
$tagins = Tagin::findOrFail($id);
dd($tagins);
// return view('venues.tagins', compact(
// 'tagins'));
}
anyone? please thank you!
Can you show the route?
And I assume 1152522 is the id?
If that id does not exist, it will throw an exception. That is what findOrFail does. Use find() instead if you don't want the error
yes thats the ID of the actual venue not the TAGIN (model) ID
here is my route:
Route::get('/venues/{id}/tagin/stats', 'VenueController@venueTaginstats')->name('venue.venuetaginstats');
I have 2 tables
TAGINS - phone_number, venue_id, ....
VENUES - id, venueName....
I have a relationship setup on these in their model files
Then why are you using it to find a tagin?
$venue = Venue::findOrFail($id);
$venue->load('tagins') ;
$tagins = $venue->tagins;
nope, still the same and 404 not found?!
Are you sure that the id exists?
$venue = Venue::find($id);
dd($venue);
I'm not getting anything?! still 404 and same error in postman
public function venueTaginstats($id) {
$venue = Venue::find($id);
$tagins = Venue::findOrFail($id)->tagins;
dd($venue);
return view('venues.tagins', compact(
'tagins'));
}
Yes.. Remove this line
$tagins = Venue::findOrFail($id)->tagins;
nope still nothing, I want to get all tagins for the venue I am currently looking at
I don't think it's actually getting to the method?!
git it now thanks! I had to move my route up the list., not sure why?!
That would be because laravel works by first match. So lets say you have another route that could match, higher up in the routes file.
Example.
Route::get('/venues/{id}/tagin/{tagId}', 'TagController@someMethod');
Route::get('/venues/{id}/tagin/stats', 'VenueController@venueTaginstats')->name('venue.venuetaginstats');
There the urlm path /venues/1152522/tagin/stats will actually match the first route, as laravel does not know if {tagId} is an integer or a word.. So it matches it to 'stats'
Please sign in or create an account to participate in this conversation.