Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Illegal string offset 'name' laravel php

Tags:

laravel

This is my view and controller of signup page. I am using laravel framework. I have checked this and it is giving error because of password field. I compiled it without password field and it worked. I am unable to understand what is the problem in it. I copied it fron laravel collective form page.

View:

{!! Form::open(['url' => 'signup/submit']) !!}
        <div class="form-group">
            {{Form::label('name', 'Name')}}
            {{Form::text('name', '', ['class' => 'form-control', 'placeholder' => 'Full Name'])}}
        </div>
        <div class="form-group">
            {{Form::label('username', 'Username')}}
            {{Form::text('username', '', ['class' => 'form-control', 'placeholder' => 'Username'])}}
        </div>
        <div class="form-group">
            {{Form::label('email', 'E-Mail Address')}}
            {{Form::email('email', '', ['class' => 'form-control', 'placeholder' => 'Your email..'])}}
        </div>
        <div class="form-group">
            {{Form::label('password', 'Password')}}
            {{Form::password('password', '123', ['class' => 'form-control', 'placeholder' => 'Password...'])}}
        </div>
        <div>
            {{Form::submit('Submit', ['class' => 'btn btn-primary'])}}
        </div>
    {!! Form::close() !!}

Controller:

public function submit(Request $request)
    {
        $this->validate($request, [
            'name' => 'required',
            'username' => 'username',
            'email' => 'email',
            'password' => 'password'
        ]);

        //Getting the info and creating new message.
        $message = new Message;
        $message->name = $request->input('name');
        $message->username = $request->input('username');
        $message->message = $request->input('email');
        $message->message = $request->input('password');

        $message->save();

        //redirecting
        return redirect('/')->with('success', 'Registeration successful');
    }

If anyone can understand the problem?

This is the error screen shot: Error screenshot

like image 344
thirteen4054 Avatar asked Apr 18 '18 14:04

thirteen4054


People also ask

What is illegal string offset in PHP?

The PHP warning: Illegal string offset happens when you try to access a string type data as if it's an array . When you try to access $myString above using an index that's not available, the PHP warning: Illegal string offset occurs.

What is illegal string offset?

The "Illegal string offset" warning when using $inputs['type'] means that the function is being passed a string instead of an array. (And then since a string offset is a number, 'type' is not suitable.)


1 Answers

Ok i found it, it's because the password field doesn't take a display value.

Change this

{{Form::password('password', '123', ['class' => 'form-control', 'placeholder' => 'Password...'])}}

to this

{{Form::password('password', ['class' => 'form-control', 'placeholder' => 'Password...'])}}

From https://laravel.io/forum/08-12-2014-illegal-string-offset-name-when-validating-against-unique

like image 87
BastienCtr Avatar answered Sep 27 '22 23:09

BastienCtr