dombg
dombg

Reputation: 331

Laravel: simple form get request returns 500 error

I have this form that I want to submit which is in the view 'blog'. Now when I navigate to the view blog it says the error message oops something.. and I get an 500 error. I'm not able to find the error..

 <form action="{{route('editBlog')}}" id="editForm{{$content->id}}" class="editForm">
                        @csrf
                        <input type="hidden" name="id" value="{{$content->id}}">
                        <input type="hidden" name="text" value="{{$content->content}}">
                        <button type="submit" class="btn-lg btn-dark">
                            <i class="fa fa-pencil" aria-hidden="true"></i>
                        </button>
                    </form>

My web.php route looks like this:

Route::get('editBlog/{id}/{text}','BlogController@edit')->name('editBlog');

And My Controller looks like this:

<?php
namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Input;


class BlogController extends Controller
{

   function edit($id,$text)
    {
        return view('edit', ['id' => $id, 'content' => $text]);
    }
}

The view edit exists and is in the right directory.

Thanks in advance!

EDIT: When I take out the code of the form, the view works fine.

Upvotes: 2

Views: 772

Answers (2)

Antony Thompson
Antony Thompson

Reputation: 1638

Can you please try doing a dump of the $text variable? I think it's just an integer, when you're expecting an object because your calling $content->id in the view? Doing this should fix the problem.

<?php   
   function edit($id, Text $text)
   {
       return view('edit', ['id' => $id, 'content' => $text]);
   }

Assuming your expecting a Text model?

Also you should get an error on the page when that happens. Can you check your .env file? Set your env to local like this:

APP_ENV=local

Upvotes: 0

Hamid Haghdoost
Hamid Haghdoost

Reputation: 867

because your route is something like this: editBlog/3/34 and your form action is this: editBlog and they are not matched with each other, change your route to sth like this:

Route::get('editBlog','BlogController@edit')->name('editBlog');

and your edit function like this:

function edit(Request $request)
{
    return view('edit', ['id' => $request->id, 'content' => $request->text]);
}

Upvotes: 3

Related Questions