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










share|improve this question





















  • What does your route definition look like?
    – Jerodev
    Nov 9 at 16:08










  • Route::resource('feestype','FeesTypesController');
    – Jahid Hasan
    Nov 9 at 16:16














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










share|improve this question





















  • What does your route definition look like?
    – Jerodev
    Nov 9 at 16:08










  • Route::resource('feestype','FeesTypesController');
    – Jahid Hasan
    Nov 9 at 16:16












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










share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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
















  • 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












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) 





share|improve this answer






















  • 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










  • 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

















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






share|improve this answer




















  • 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 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











  • the output of dd is added in my next answer
    – Jahid Hasan
    Nov 9 at 17:04

















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 [▶]






share|improve this answer




















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













     

    draft saved


    draft discarded


















    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

























    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) 





    share|improve this answer






















    • 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










    • 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














    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) 





    share|improve this answer






















    • 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










    • 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












    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) 





    share|improve this answer














    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) 






    share|improve this answer














    share|improve this answer



    share|improve this answer








    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










    • 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










    • 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










    • 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










    • 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












    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






    share|improve this answer




















    • 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 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











    • the output of dd is added in my next answer
      – Jahid Hasan
      Nov 9 at 17:04














    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






    share|improve this answer




















    • 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 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











    • the output of dd is added in my next answer
      – Jahid Hasan
      Nov 9 at 17:04












    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






    share|improve this answer












    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







    share|improve this answer












    share|improve this answer



    share|improve this answer










    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 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











    • 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










    • 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










    • 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










    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 [▶]






    share|improve this answer
























      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 [▶]






      share|improve this answer






















        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 [▶]






        share|improve this answer












        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 [▶]







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 9 at 17:04









        Jahid Hasan

        15




        15



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Use pre created SQLite database for Android project in kotlin

            Darth Vader #20

            Ondo