0

I am trying to insert data in my database.But I can't to do it. I try my best. I know its a simple question. Here is my route:

Route::post('/class', [
'uses' => 'classroom@showdata',
'as' => 'classrooms']);

Here is my Controller:

public function showclass(Request $request)
{
    $randomnumber = rand(50001,1000000);

    $classrooms = new Classrooms();
    $classrooms->class_name = $request['class_name'];
    $classrooms->subject_name = $request['subject_name'];
    $classrooms->section = $request['section'];
    $classrooms->class_code = $randomnumber;
    $classrooms -> user_id = Auth::user()->id;
    $classrooms -> save();
    return view('class', array('classroom' => Auth::user()) );
}

Here is my form:

<form class="form-horizontal" role="form" method="POST" action="{{ url('/class') }}">
                    {!! csrf_field() !!}

Where is my mistake?

1
  • Make sure you have the debug set to true in your config/app.php. Then wait for the stack trace of the thrown exception (if any, but highly likely) to know the cause. Aug 21, 2016 at 20:35

1 Answer 1

1

There is an error in your Route. You have used showdata method instead of showclass. Just change it like below:

Route::post('/class', [
'uses' => 'classroom@showclass',
'as' => 'classrooms']);

Note: Make sure to specify specific method while defining the routes.

11
  • can you check if your function is executing ? use die();
    – jaysingkar
    Aug 21, 2016 at 21:26
  • how its used i don't know. there is most funny things is i have a another blade page dashboard.blade.php if i changed in route url ... controller return and form action in dashboard its works
    – Shuvo
    Aug 21, 2016 at 21:29
  • your previous question.stackoverflow.com/questions/39067623/…
    – jaysingkar
    Aug 21, 2016 at 21:31
  • can you post dashboard route and method used ?
    – jaysingkar
    Aug 21, 2016 at 21:31
  • to use die() add die('hello'); in your above method.
    – jaysingkar
    Aug 21, 2016 at 21:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.