Search code examples
phplaravelformspost

Trying to get property 'POST /employee HTTP/1.1


I have created a laravel application to store employee data, but when I submit the form it gives me the following error, what should I do to avoid this problem. thanks

Error Exception

This is my EmployeeController store method

    public function store(Request $request)
{
        $this->validate($request,array(
            'lastname'=>'required|max:60',
            'firstname'=>'required|max:60',
            'middlename'=>'required|max:60',
            'address'=>'required|max:120',
            'NIC'=>'required|max:10',
            'city_id'=>'required|max:60',
            'state_id'=>'required|max:60',
            'mobile'=>'required|max:10',
            'email'=>'required|max:60',
            'postal_code'=>'required|max:10',
            'birthdate'=>'required|date',
            'date_hired'=>'required|date',
            'department_id'=>'required|max:10',


    ));
    $employee = new Employee();
    $employee->lastname=$request->lastname;
    $employee->firstname=$request->firstname;
    $employee->middlename=$request->middlename;
    $employee->address=$request->address;
    $employee->NIC=$request->NIC;
    $employee->city_id=$request->city_id;
    $employee->state_id=$request->state_id;
    $employee->mobile=$request->mobile;
    $employee->email->$request->email;
    $employee->postal_code=$request->postal_code;
    $employee->birthdate=$request->birthdate;
    $employee->date_hired=$request->date_hired;
    $employee->department_id=$request->department_id;

    $employee->save();
}

Form header

{!! Form::open(['route'=>'employee.store','class'=>'form-horizontal p-t-20']) !!}

Classes i used for the controller

namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Department;
use Illuminate\Support\Facades\DB;
use App\Employee;

Solution

  • There is an error in your code.

       $employee->email->$request->email;
    

    This should be,

       $employee->email = $request->email;