Laravel 5.6 error "function name must be a string" with builtin Auth

时间:2018-06-20 05:05:46

标签: laravel-blade laravel-5.6 laravel-authentication

Im trying to modified the builtin laravel Auth to take in more attribute, but have encountered the error "function name must be a string". I didnt know what i did wrong.

Here's my create method:

protected function create(array $data)
    {
        $imgPath = Storage::putFile('public/photos/users', $data('image'));
        $imgPath = 'photos/users/' . basename($imgPath);

        return User::create([
            'imgPath' => $imgPath,
            'firstName' => $data['firstName'],
            'lastName' => $data['lastName'],
            'about' => $data['about'],
            'email' => $data['email'],
            'username' => $data['username'],
            'password' => Hash::make($data['password']),
            'role' => $data['role'],
            'province_id' => $data['province_id'],
        ]);
    }

the error show the that the part where i try to store image to $imgPath is where exception occured but i dont know whats wrong there. I used the same code for many time, worked fine. Here's my register view:

@extends('layouts.app')

@section('content')
<div class="container">
    <div class="row justify-content-center">
        <div class="col-md-8">
            <div class="card">
                <div class="card-header">{{ __('Register') }}</div>

                <div class="card-body">
                    <form method="POST" action="{{ route('register') }}">
                        @csrf

                        <div class="input-group mb-3">
                            <div class="custom-file">
                                <label class="custom-file-label" for="image">Upload a picture of yourself</label>
                                <input type="file" class="custom-file-input" id="image" name="image" required>
                            </div>
                        </div>

                        <div class="form-group row">
                            <label for="firstName" class="col-md-4 col-form-label text-md-right">{{ __('First Name') }}</label>

                            <div class="col-md-6">
                                <input id="firstName" type="text" class="form-control{{ $errors->has('firstName') ? ' is-invalid' : '' }}" name="firstName" value="{{ old('firstName') }}" required autofocus>

                                @if ($errors->has('firstName'))
                                    <span class="invalid-feedback">
                                        <strong>{{ $errors->first('firstName') }}</strong>
                                    </span>
                                @endif
                            </div>
                        </div>

                        <div class="form-group row">
                            <label for="lastName" class="col-md-4 col-form-label text-md-right">{{ __('Last Name') }}</label>

                            <div class="col-md-6">
                                <input id="lastName" type="text" class="form-control{{ $errors->has('lastName') ? ' is-invalid' : '' }}" name="lastName" value="{{ old('lastName') }}" required autofocus>

                                @if ($errors->has('lastName'))
                                    <span class="invalid-feedback">
                                        <strong>{{ $errors->first('lastName') }}</strong>
                                    </span>
                                @endif
                            </div>
                        </div>

                        <div class="form-group row">
                            <label for="about" class="col-md-4 col-form-label text-md-right">{{ __('About You') }}</label>
                            <div class="col-md-6">
                                <textarea placeholder="Tell us something about yourself"
                                          id="about"
                                          name="about"
                                          required autofocus
                                          rows="5" spellcheck="true"
                                          class="form-control{{ $errors->has('about') ? ' is-invalid' : '' }} autosize-target text-left ">{{ old('about') }}</textarea>

                                @if ($errors->has('about'))
                                    <span class="invalid-feedback">
                                        <strong>{{ $errors->first('about') }}</strong>
                                    </span>
                                @endif
                            </div>
                        </div>

                        <div class="form-group row">
                            <label for="email" class="col-md-4 col-form-label text-md-right">{{ __('E-Mail Address') }}</label>

                            <div class="col-md-6">
                                <input id="email" type="email" class="form-control{{ $errors->has('email') ? ' is-invalid' : '' }}" name="email" value="{{ old('email') }}" required>

                                @if ($errors->has('email'))
                                    <span class="invalid-feedback">
                                        <strong>{{ $errors->first('email') }}</strong>
                                    </span>
                                @endif
                            </div>
                        </div>

                        <div class="form-group row">
                            <label for="username" class="col-md-4 col-form-label text-md-right">{{ __('Username') }}</label>

                            <div class="col-md-6">
                                <input id="username" class="form-control{{ $errors->has('username') ? ' is-invalid' : '' }}" name="username" value="{{ old('username') }}" required>

                                @if ($errors->has('username'))
                                    <span class="invalid-feedback">
                                        <strong>{{ $errors->first('username') }}</strong>
                                    </span>
                                @endif
                            </div>
                        </div>

                        <div class="form-group row">
                            <label for="password" class="col-md-4 col-form-label text-md-right">{{ __('Password') }}</label>

                            <div class="col-md-6">
                                <input id="password" type="password" class="form-control{{ $errors->has('password') ? ' is-invalid' : '' }}" name="password" required>

                                @if ($errors->has('password'))
                                    <span class="invalid-feedback">
                                        <strong>{{ $errors->first('password') }}</strong>
                                    </span>
                                @endif
                            </div>
                        </div>

                        <div class="form-group row">
                            <label for="password-confirm" class="col-md-4 col-form-label text-md-right">{{ __('Confirm Password') }}</label>

                            <div class="col-md-6">
                                <input id="password-confirm" type="password" class="form-control" name="password_confirmation" required>
                            </div>
                        </div>

                        <div class="form-group row mb-0">
                            <div class="col-md-6 offset-md-4">
                                <button type="submit" class="btn btn-primary">
                                    {{ __('Register') }}
                                </button>
                            </div>
                        </div>

                        <input type="hidden" name="role" value="guide" />
                        <input type="hidden" name="province_id" value="1" />
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection

1 个答案:

答案 0 :(得分:0)

您可以更改

SQL> alter session set nls_date_format = 'dd.mm.yyyy';

Session altered.

SQL> select extract (year from add_months (date '2016-01-01', (level - 1) * 6)) year,
  2         add_months (date '2016-01-01', (level - 1) * 6) start_date,
  3         add_months (date '2016-01-01', (level) * 6) - 1 end_date
  4  from dual
  5  connect by level <= (extract (year from sysdate) - 2016 + 1) * 2;

      YEAR START_DATE END_DATE
---------- ---------- ----------
      2016 01.01.2016 30.06.2016
      2016 01.07.2016 31.12.2016
      2017 01.01.2017 30.06.2017
      2017 01.07.2017 31.12.2017
      2018 01.01.2018 30.06.2018
      2018 01.07.2018 31.12.2018

6 rows selected.

SQL>

$data('image')

因为$data['image'] 是一个数组,而不是一个函数。