I get the NotFoundHttpException in RouteCollection.php line 161:
but I can't find the error. I'm using Laravel 5.4.
I ran php artisan route:list
command and I see the defined (named) route.
And here is the route file.
<?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('/', 'LinkController@create');
Route::post('/create', 'LinkController@store');
Route::get('show/{id}', 'LinkController@show')->name('show');
And here is the part from the resource controller.
public function store(Request $request)
{
$this->validate($request, [
'url' => 'required|url'
]);
// Generate string length of 6 characters
$newHash = Str::random(6);
// creates a $link object
$link = new Link;
//checks if link already exists in the database
$link_in_db = DB::table('links')->where('url', '=', $request->url)->get();
if($link_in_db === null){
// sets the $link variables
$link->url = $request->url;
$link->hash = $newHash;
// $link is saved in the database
$link->save();
// redirects to the route
return redirect()->route('show', $link->id);
}else{ // link is in the database
// print_r($link_in_db); // testing purposes
return redirect()->route('show', $link->id);
}
}
And I highly appreciate any suggestion. If there are any other methods to redirect with data, please suggest.
Thank you!
via Isuru