Below in my web.php
content
Route::get('/tripScheduler', 'trip_scheduler@index')->name('listTripSche');
Route::post('/tripScheduler/create', 'trip_scheduler@store')->name('saveTripSche');
Route::get('/tripScheduler/create', 'trip_scheduler@create');
Route::get('/tripScheduler/{sche}', 'trip_scheduler@show');
Below is my controller file(trip_scheduler.php
)
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Validator;
use Redirect;
use DB;
use Illuminate\Support\Facades\Auth;
class trip_scheduler extends Controller
{
public function __construct(){
$this->middleware('auth');
}
public function show(trip_scheduler $sche){
print_r($sche);
}
}
Now when I visite mysite.com/tripScheduler/1
, it should show me the record from database where id is 1. However, it is giving the following output for print_r($sche)
App\Http\Controllers\trip_scheduler Object (
[middleware:protected] => Array (
[0] => Array (
[middleware] => auth
[options] => Array ( )
)
)
)
I am not sure where I am going wrong. Thanks in advance for your help!
Your show function like:
use trip_scheduler;
public function show(trip_scheduler $sche){
print_r($sche);
}
NOTE: trip_scheduler
is your model name
OR
public function show($sche){
$rsltTrip = trip_scheduler::find($sche);
print_r($rsltTrip);
}
You are type hinting your controller trip_scheduler $sche
which is why print_r
displaying trip_scheduler
controller class. Try this way
class trip_scheduler extends Controller
{
public function __construct(){
$this->middleware('auth');
}
public function show($sche){
$resp = YourModal::find($sche);
return response($resp);
}
}