Laravel not throwing error saving

Published 1 week ago by ArthurDiniz

Hi, im developing my first project, and when i try to save a service it does not save. It just refresh the create page.

Create View

{!! Form::open(['route' => '','method' => 'post']) !!}
                    {{ Form::label('name','Name:')}}
                    {{ Form::text('name',null,array('class' => 'form-control','required' => '', 'maxlenght' => '50'))}}

                    {{ Form::label('users_id','User:',['style'=>'margin-top: 20px;'])}}
                    {{ Form::text('users_id',$user->id,['disabled'=>'disabled','class' => 'form-control','required' => '', 'maxlenght' => '10'])}}

                    {{ Form::label('phone','Phone:',['style'=>'margin-top: 20px;'])}}
                    {{ Form::text('phone',null,array('class' => 'form-control','required' => '', 'maxlenght' => '10'))}}

                    {{ Form::label('razsocial','Raz Social:')}}
                    {{ Form::text('razsocial',null,array('class' => 'form-control','required' => '', 'maxlenght' => '50'))}}

                    {{ Form::label('seller','Seller:')}}
                    {{ Form::text('seller',null,array('class' => 'form-control','required' => '', 'maxlenght' => '50'))}}     

                    {{ Form::label('sellerphone','Seller Phone:')}}
                    {{ Form::text('sellerphone',null,array('class' => 'form-control','required' => '', 'maxlenght' => '10'))}}                     

                    {{ Form::submit('Create Service',array('class' => 'btn btn-success btn-lg btn-block','style' => 'margin-top: 20px;'))}}
                    {!! Form::close() !!}


public function create()
        $user = Auth::user();
        return view('services.create')->withUser($user);

     * Store a newly created resource in storage.
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
    public function store(Request $request)
        //Validate de data
        $this->validate($request, array(
                'name'        => 'required|max:45',
                'phone'       => 'required|max:10',
                'users_id'    => 'required|integer',
                'razsocial'   => 'required|max:50',
                'seller'      => 'required|max:50',
                'sellerphone' => 'required|max:10',

        //Store in the Database
        $service = new Service;

        $service->name = $request->name;
        $service->phone = $request->phone;
        $service->users_id = $request->users_id;
        $service->razsocial  = $request->razsocial;
        $service->seller = $request->seller;
        $service->sellerphone = $request->sellerphone;


        Session::flash('success','The service was succesfully save!');

        //Redirect to Another Page
        return redirect()->route('', $service->id);


There are lots of missing information:

Maybe you missed the csrf-token-field?

{{ csrf_field() }}

What u mean by missing information?

im sorry my english is poor


@ArthurDiniz Information like, how you registered your routes etc. But I think you use resource-routes, so check if the missing csrf-field will do it.


How do i implement csrf-field? Do i put at the end of the form? Yes i used resource-routes


@vanderb solved it! Thx! the problem was in this line


 {{ Form::text('users_id',$user->id,['disabled'=>'disabled','class' => 'form-control','required' => '', 'maxlenght' => '10'])}}

I deleted the 'disabled'


{{ Form::text('users_id',$user->id,['class' => 'form-control','required' => '', 'maxlenght' => '10'])}}

But how can i block the field so users can not edit?


I would remove it. you should not expose the user's id


Do you have user authentication?


But i want to save on the database. How can i pass it without the form? Yes i have


Instead of this

$service->users_id = $request->users_id;

do this

$service->users_id = $request->user()->id;

And in the view i delete the user form?


Yes delete this part

{{ Form::text('users_id',$user->id,['class' => 'form-control','required' => '', 'maxlenght' => '10'])}}

It should still work fine


Thx it work also deleted it

'users_id'    => 'required|integer',



@spodlogar can u explain somethin? do i need to use

    $user = Auth::user();
        return view('services.create')->withUser($user);

in every function , controller?


The 'disabled' attribute on an html input field will not send the data through for the field when the form is submitted. Use the 'readonly' attribute in place of that instead and it will send the data through but not allow a user to edit.

However, id recommend removing that field completely from the form, unless you have a good reason for users to see these id. If these user id's are associated with other users than who's logged in, make it a hidden field.

If this user_id is always from the logged in user, then do something like this in the controller:

 $service->users_id = Auth::user()->id;

Sign In or create a forum account to participate in this discussion.