So I thought I'd make this a different title name since there are so many as it relates to the "error" message: No query results for model [App\WaitList].
What I'd really like to know, is not WHAT that message means, but how to handle it better.
Essentially I want to be able to pass an id to the show controller then either return a view displaying the related model's info, OR return a view stating that the model doesn't exist (in this case a user/waitlister) then offer the option to join the waitlist.
Here is my current routes/web.php
<?php
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('/', function () {
return view('welcome');
});
Auth::routes();
Route::get('/waitlist/join', 'WaitListController@create');
Route::resource('waitlist', 'WaitListController', [
'only' =>
['show', 'store', 'destroy']
]);
Here is my current WaitListController
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Mail;
use App\WaitList;
use App\Http\Requests\WaitlistRequest;
use App\Mail\WaitListWelcome;
class WaitListController extends Controller
{
public function create()
{
return view('waitlist.create');
}
public function store(WaitListRequest $request)
{
//store in DB
$waitlist = WaitList::create(
request(['name', 'email'])
);
Mail::to($waitlist)->send(new WaitListWelcome($waitlist));
session()->flash('message', 'Thanks for joining the wait list!');
return redirect('/');
//redirect
}
public function show(WaitList $waitlist){
return view('waitlist.show', compact('waitlist'));
}
}
As one would expect this works fine when a row exists in the waitlist table that matches the id I pass, but when it doesn't I get the standard laravel message telling me:
(2/2) NotFoundHttpException
No query results for model [App\WaitList].
from playing with die & dumps it looks like this is thrown before anything inside the control method executes.
Any ideas on how I can handle this?