Passing data from blade to controller Laravel
up vote
0
down vote
favorite
I want to pass a object from the blade file to the controller file. The purpose is when the user click an edit button the user will get a form which is filled with the previous input data. I am using this code in the blade file:
<a href="/feestype/ $feesType->id /edit" class="btn btn-info btn-sm">Edit</a>
But When I want to get the passed object from the controller's edit method I get a null. My Controller code is like this now:
public function edit(FeesType $feesType)
//
dump($feesType->name);
return view('feestype.edit',['feesType'=>$feesType]);
Here I have dump the $feesType object but I get a null. Please help me how can I solve this problem.
Thanks in advance
php laravel controller laravel-blade
add a comment |
up vote
0
down vote
favorite
I want to pass a object from the blade file to the controller file. The purpose is when the user click an edit button the user will get a form which is filled with the previous input data. I am using this code in the blade file:
<a href="/feestype/ $feesType->id /edit" class="btn btn-info btn-sm">Edit</a>
But When I want to get the passed object from the controller's edit method I get a null. My Controller code is like this now:
public function edit(FeesType $feesType)
//
dump($feesType->name);
return view('feestype.edit',['feesType'=>$feesType]);
Here I have dump the $feesType object but I get a null. Please help me how can I solve this problem.
Thanks in advance
php laravel controller laravel-blade
What does your route definition look like?
– Jerodev
Nov 9 at 16:08
Route::resource('feestype','FeesTypesController');
– Jahid Hasan
Nov 9 at 16:16
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I want to pass a object from the blade file to the controller file. The purpose is when the user click an edit button the user will get a form which is filled with the previous input data. I am using this code in the blade file:
<a href="/feestype/ $feesType->id /edit" class="btn btn-info btn-sm">Edit</a>
But When I want to get the passed object from the controller's edit method I get a null. My Controller code is like this now:
public function edit(FeesType $feesType)
//
dump($feesType->name);
return view('feestype.edit',['feesType'=>$feesType]);
Here I have dump the $feesType object but I get a null. Please help me how can I solve this problem.
Thanks in advance
php laravel controller laravel-blade
I want to pass a object from the blade file to the controller file. The purpose is when the user click an edit button the user will get a form which is filled with the previous input data. I am using this code in the blade file:
<a href="/feestype/ $feesType->id /edit" class="btn btn-info btn-sm">Edit</a>
But When I want to get the passed object from the controller's edit method I get a null. My Controller code is like this now:
public function edit(FeesType $feesType)
//
dump($feesType->name);
return view('feestype.edit',['feesType'=>$feesType]);
Here I have dump the $feesType object but I get a null. Please help me how can I solve this problem.
Thanks in advance
php laravel controller laravel-blade
php laravel controller laravel-blade
asked Nov 9 at 16:03
Jahid Hasan
15
15
What does your route definition look like?
– Jerodev
Nov 9 at 16:08
Route::resource('feestype','FeesTypesController');
– Jahid Hasan
Nov 9 at 16:16
add a comment |
What does your route definition look like?
– Jerodev
Nov 9 at 16:08
Route::resource('feestype','FeesTypesController');
– Jahid Hasan
Nov 9 at 16:16
What does your route definition look like?
– Jerodev
Nov 9 at 16:08
What does your route definition look like?
– Jerodev
Nov 9 at 16:08
Route::resource('feestype','FeesTypesController');
– Jahid Hasan
Nov 9 at 16:16
Route::resource('feestype','FeesTypesController');
– Jahid Hasan
Nov 9 at 16:16
add a comment |
3 Answers
3
active
oldest
votes
up vote
1
down vote
Route model binding works a bit different here is the documentation
What you need to do is have your route like this:
Route::get('feestype/feesType/edit', 'YourController@edit')->name('feestype.edit');
then in your view
<a href=" route('feestype.edit', $feesType) " class="btn btn-info btn-sm">Edit</a>
-- EDIT
using a resource file:
Route::resource('feestype', 'YourController')
the link will be built the same as above:
route('feestype.edit', $feesType)
I have used a resource route
– Jahid Hasan
Nov 9 at 16:12
usephp artisan route:list
it will show you the route name that you are using. And then use that within theroute
helper function that I am using above it will be the same
– nakov
Nov 9 at 16:13
look at my edit.
– nakov
Nov 9 at 16:16
after using your code I get a new error when dumping: "Trying to get property 'id' of non-object"
– Jahid Hasan
Nov 9 at 16:25
you get that in the controller?
– nakov
Nov 9 at 16:27
|
show 8 more comments
up vote
0
down vote
Now the code in the blade file is
<a href=" route('feestype.edit',$feesType) " class="btn btn-info btn-sm">Edit</a>
The controller file contains this code:
public function edit(FeesType $feesType)
//
$feesType = FeesType::find($feesType->id);
dump($feesType->name);
return view('feestype.edit',['feesType'=>$feesType]);
And here is my Route definition:
Route::resource('feestype','FeesTypesController');
And the browser shows this message:
enter image description here
And what is your error message? btw, you don't have to do this again$feesType = FeesType::find($feesType->id);
that's why model binding is for, so the$feesType
parameter should already be full.
– nakov
Nov 9 at 16:54
after removing that line it doesn't show that error message now but the object contains null again
– Jahid Hasan
Nov 9 at 16:56
try usingdd
instead ofdump
because I don't know if the problem is in the controller method or somewhere in the view that you are showing.
– nakov
Nov 9 at 16:58
And please follow the documentation link that I've shared in my answer to resolve your issue, because it is really hard to find the problem like this. We will spend a whole day.
– nakov
Nov 9 at 16:59
the output of dd is added in my next answer
– Jahid Hasan
Nov 9 at 17:04
|
show 3 more comments
up vote
0
down vote
FeesType #283 ▼
#fillable: array:2 [▶]
#connection: null
#table: null
#primaryKey: "id"
#keyType: "int"
+incrementing: true
#with:
#withCount:
#perPage: 15
+exists: false
+wasRecentlyCreated: false
#attributes:
#original:
#changes:
#casts:
#dates:
#dateFormat: null
#appends:
#dispatchesEvents:
#observables:
#relations:
#touches:
+timestamps: true
#hidden:
#visible:
#guarded: array:1 [▶]
add a comment |
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
Route model binding works a bit different here is the documentation
What you need to do is have your route like this:
Route::get('feestype/feesType/edit', 'YourController@edit')->name('feestype.edit');
then in your view
<a href=" route('feestype.edit', $feesType) " class="btn btn-info btn-sm">Edit</a>
-- EDIT
using a resource file:
Route::resource('feestype', 'YourController')
the link will be built the same as above:
route('feestype.edit', $feesType)
I have used a resource route
– Jahid Hasan
Nov 9 at 16:12
usephp artisan route:list
it will show you the route name that you are using. And then use that within theroute
helper function that I am using above it will be the same
– nakov
Nov 9 at 16:13
look at my edit.
– nakov
Nov 9 at 16:16
after using your code I get a new error when dumping: "Trying to get property 'id' of non-object"
– Jahid Hasan
Nov 9 at 16:25
you get that in the controller?
– nakov
Nov 9 at 16:27
|
show 8 more comments
up vote
1
down vote
Route model binding works a bit different here is the documentation
What you need to do is have your route like this:
Route::get('feestype/feesType/edit', 'YourController@edit')->name('feestype.edit');
then in your view
<a href=" route('feestype.edit', $feesType) " class="btn btn-info btn-sm">Edit</a>
-- EDIT
using a resource file:
Route::resource('feestype', 'YourController')
the link will be built the same as above:
route('feestype.edit', $feesType)
I have used a resource route
– Jahid Hasan
Nov 9 at 16:12
usephp artisan route:list
it will show you the route name that you are using. And then use that within theroute
helper function that I am using above it will be the same
– nakov
Nov 9 at 16:13
look at my edit.
– nakov
Nov 9 at 16:16
after using your code I get a new error when dumping: "Trying to get property 'id' of non-object"
– Jahid Hasan
Nov 9 at 16:25
you get that in the controller?
– nakov
Nov 9 at 16:27
|
show 8 more comments
up vote
1
down vote
up vote
1
down vote
Route model binding works a bit different here is the documentation
What you need to do is have your route like this:
Route::get('feestype/feesType/edit', 'YourController@edit')->name('feestype.edit');
then in your view
<a href=" route('feestype.edit', $feesType) " class="btn btn-info btn-sm">Edit</a>
-- EDIT
using a resource file:
Route::resource('feestype', 'YourController')
the link will be built the same as above:
route('feestype.edit', $feesType)
Route model binding works a bit different here is the documentation
What you need to do is have your route like this:
Route::get('feestype/feesType/edit', 'YourController@edit')->name('feestype.edit');
then in your view
<a href=" route('feestype.edit', $feesType) " class="btn btn-info btn-sm">Edit</a>
-- EDIT
using a resource file:
Route::resource('feestype', 'YourController')
the link will be built the same as above:
route('feestype.edit', $feesType)
edited Nov 9 at 16:16
answered Nov 9 at 16:08
nakov
1,26388
1,26388
I have used a resource route
– Jahid Hasan
Nov 9 at 16:12
usephp artisan route:list
it will show you the route name that you are using. And then use that within theroute
helper function that I am using above it will be the same
– nakov
Nov 9 at 16:13
look at my edit.
– nakov
Nov 9 at 16:16
after using your code I get a new error when dumping: "Trying to get property 'id' of non-object"
– Jahid Hasan
Nov 9 at 16:25
you get that in the controller?
– nakov
Nov 9 at 16:27
|
show 8 more comments
I have used a resource route
– Jahid Hasan
Nov 9 at 16:12
usephp artisan route:list
it will show you the route name that you are using. And then use that within theroute
helper function that I am using above it will be the same
– nakov
Nov 9 at 16:13
look at my edit.
– nakov
Nov 9 at 16:16
after using your code I get a new error when dumping: "Trying to get property 'id' of non-object"
– Jahid Hasan
Nov 9 at 16:25
you get that in the controller?
– nakov
Nov 9 at 16:27
I have used a resource route
– Jahid Hasan
Nov 9 at 16:12
I have used a resource route
– Jahid Hasan
Nov 9 at 16:12
use
php artisan route:list
it will show you the route name that you are using. And then use that within the route
helper function that I am using above it will be the same– nakov
Nov 9 at 16:13
use
php artisan route:list
it will show you the route name that you are using. And then use that within the route
helper function that I am using above it will be the same– nakov
Nov 9 at 16:13
look at my edit.
– nakov
Nov 9 at 16:16
look at my edit.
– nakov
Nov 9 at 16:16
after using your code I get a new error when dumping: "Trying to get property 'id' of non-object"
– Jahid Hasan
Nov 9 at 16:25
after using your code I get a new error when dumping: "Trying to get property 'id' of non-object"
– Jahid Hasan
Nov 9 at 16:25
you get that in the controller?
– nakov
Nov 9 at 16:27
you get that in the controller?
– nakov
Nov 9 at 16:27
|
show 8 more comments
up vote
0
down vote
Now the code in the blade file is
<a href=" route('feestype.edit',$feesType) " class="btn btn-info btn-sm">Edit</a>
The controller file contains this code:
public function edit(FeesType $feesType)
//
$feesType = FeesType::find($feesType->id);
dump($feesType->name);
return view('feestype.edit',['feesType'=>$feesType]);
And here is my Route definition:
Route::resource('feestype','FeesTypesController');
And the browser shows this message:
enter image description here
And what is your error message? btw, you don't have to do this again$feesType = FeesType::find($feesType->id);
that's why model binding is for, so the$feesType
parameter should already be full.
– nakov
Nov 9 at 16:54
after removing that line it doesn't show that error message now but the object contains null again
– Jahid Hasan
Nov 9 at 16:56
try usingdd
instead ofdump
because I don't know if the problem is in the controller method or somewhere in the view that you are showing.
– nakov
Nov 9 at 16:58
And please follow the documentation link that I've shared in my answer to resolve your issue, because it is really hard to find the problem like this. We will spend a whole day.
– nakov
Nov 9 at 16:59
the output of dd is added in my next answer
– Jahid Hasan
Nov 9 at 17:04
|
show 3 more comments
up vote
0
down vote
Now the code in the blade file is
<a href=" route('feestype.edit',$feesType) " class="btn btn-info btn-sm">Edit</a>
The controller file contains this code:
public function edit(FeesType $feesType)
//
$feesType = FeesType::find($feesType->id);
dump($feesType->name);
return view('feestype.edit',['feesType'=>$feesType]);
And here is my Route definition:
Route::resource('feestype','FeesTypesController');
And the browser shows this message:
enter image description here
And what is your error message? btw, you don't have to do this again$feesType = FeesType::find($feesType->id);
that's why model binding is for, so the$feesType
parameter should already be full.
– nakov
Nov 9 at 16:54
after removing that line it doesn't show that error message now but the object contains null again
– Jahid Hasan
Nov 9 at 16:56
try usingdd
instead ofdump
because I don't know if the problem is in the controller method or somewhere in the view that you are showing.
– nakov
Nov 9 at 16:58
And please follow the documentation link that I've shared in my answer to resolve your issue, because it is really hard to find the problem like this. We will spend a whole day.
– nakov
Nov 9 at 16:59
the output of dd is added in my next answer
– Jahid Hasan
Nov 9 at 17:04
|
show 3 more comments
up vote
0
down vote
up vote
0
down vote
Now the code in the blade file is
<a href=" route('feestype.edit',$feesType) " class="btn btn-info btn-sm">Edit</a>
The controller file contains this code:
public function edit(FeesType $feesType)
//
$feesType = FeesType::find($feesType->id);
dump($feesType->name);
return view('feestype.edit',['feesType'=>$feesType]);
And here is my Route definition:
Route::resource('feestype','FeesTypesController');
And the browser shows this message:
enter image description here
Now the code in the blade file is
<a href=" route('feestype.edit',$feesType) " class="btn btn-info btn-sm">Edit</a>
The controller file contains this code:
public function edit(FeesType $feesType)
//
$feesType = FeesType::find($feesType->id);
dump($feesType->name);
return view('feestype.edit',['feesType'=>$feesType]);
And here is my Route definition:
Route::resource('feestype','FeesTypesController');
And the browser shows this message:
enter image description here
answered Nov 9 at 16:50
Jahid Hasan
15
15
And what is your error message? btw, you don't have to do this again$feesType = FeesType::find($feesType->id);
that's why model binding is for, so the$feesType
parameter should already be full.
– nakov
Nov 9 at 16:54
after removing that line it doesn't show that error message now but the object contains null again
– Jahid Hasan
Nov 9 at 16:56
try usingdd
instead ofdump
because I don't know if the problem is in the controller method or somewhere in the view that you are showing.
– nakov
Nov 9 at 16:58
And please follow the documentation link that I've shared in my answer to resolve your issue, because it is really hard to find the problem like this. We will spend a whole day.
– nakov
Nov 9 at 16:59
the output of dd is added in my next answer
– Jahid Hasan
Nov 9 at 17:04
|
show 3 more comments
And what is your error message? btw, you don't have to do this again$feesType = FeesType::find($feesType->id);
that's why model binding is for, so the$feesType
parameter should already be full.
– nakov
Nov 9 at 16:54
after removing that line it doesn't show that error message now but the object contains null again
– Jahid Hasan
Nov 9 at 16:56
try usingdd
instead ofdump
because I don't know if the problem is in the controller method or somewhere in the view that you are showing.
– nakov
Nov 9 at 16:58
And please follow the documentation link that I've shared in my answer to resolve your issue, because it is really hard to find the problem like this. We will spend a whole day.
– nakov
Nov 9 at 16:59
the output of dd is added in my next answer
– Jahid Hasan
Nov 9 at 17:04
And what is your error message? btw, you don't have to do this again
$feesType = FeesType::find($feesType->id);
that's why model binding is for, so the $feesType
parameter should already be full.– nakov
Nov 9 at 16:54
And what is your error message? btw, you don't have to do this again
$feesType = FeesType::find($feesType->id);
that's why model binding is for, so the $feesType
parameter should already be full.– nakov
Nov 9 at 16:54
after removing that line it doesn't show that error message now but the object contains null again
– Jahid Hasan
Nov 9 at 16:56
after removing that line it doesn't show that error message now but the object contains null again
– Jahid Hasan
Nov 9 at 16:56
try using
dd
instead of dump
because I don't know if the problem is in the controller method or somewhere in the view that you are showing.– nakov
Nov 9 at 16:58
try using
dd
instead of dump
because I don't know if the problem is in the controller method or somewhere in the view that you are showing.– nakov
Nov 9 at 16:58
And please follow the documentation link that I've shared in my answer to resolve your issue, because it is really hard to find the problem like this. We will spend a whole day.
– nakov
Nov 9 at 16:59
And please follow the documentation link that I've shared in my answer to resolve your issue, because it is really hard to find the problem like this. We will spend a whole day.
– nakov
Nov 9 at 16:59
the output of dd is added in my next answer
– Jahid Hasan
Nov 9 at 17:04
the output of dd is added in my next answer
– Jahid Hasan
Nov 9 at 17:04
|
show 3 more comments
up vote
0
down vote
FeesType #283 ▼
#fillable: array:2 [▶]
#connection: null
#table: null
#primaryKey: "id"
#keyType: "int"
+incrementing: true
#with:
#withCount:
#perPage: 15
+exists: false
+wasRecentlyCreated: false
#attributes:
#original:
#changes:
#casts:
#dates:
#dateFormat: null
#appends:
#dispatchesEvents:
#observables:
#relations:
#touches:
+timestamps: true
#hidden:
#visible:
#guarded: array:1 [▶]
add a comment |
up vote
0
down vote
FeesType #283 ▼
#fillable: array:2 [▶]
#connection: null
#table: null
#primaryKey: "id"
#keyType: "int"
+incrementing: true
#with:
#withCount:
#perPage: 15
+exists: false
+wasRecentlyCreated: false
#attributes:
#original:
#changes:
#casts:
#dates:
#dateFormat: null
#appends:
#dispatchesEvents:
#observables:
#relations:
#touches:
+timestamps: true
#hidden:
#visible:
#guarded: array:1 [▶]
add a comment |
up vote
0
down vote
up vote
0
down vote
FeesType #283 ▼
#fillable: array:2 [▶]
#connection: null
#table: null
#primaryKey: "id"
#keyType: "int"
+incrementing: true
#with:
#withCount:
#perPage: 15
+exists: false
+wasRecentlyCreated: false
#attributes:
#original:
#changes:
#casts:
#dates:
#dateFormat: null
#appends:
#dispatchesEvents:
#observables:
#relations:
#touches:
+timestamps: true
#hidden:
#visible:
#guarded: array:1 [▶]
FeesType #283 ▼
#fillable: array:2 [▶]
#connection: null
#table: null
#primaryKey: "id"
#keyType: "int"
+incrementing: true
#with:
#withCount:
#perPage: 15
+exists: false
+wasRecentlyCreated: false
#attributes:
#original:
#changes:
#casts:
#dates:
#dateFormat: null
#appends:
#dispatchesEvents:
#observables:
#relations:
#touches:
+timestamps: true
#hidden:
#visible:
#guarded: array:1 [▶]
answered Nov 9 at 17:04
Jahid Hasan
15
15
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53229271%2fpassing-data-from-blade-to-controller-laravel%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What does your route definition look like?
– Jerodev
Nov 9 at 16:08
Route::resource('feestype','FeesTypesController');
– Jahid Hasan
Nov 9 at 16:16