score:0

the error message tells you that you are overriding the create method in the clientformrequest class. so remove the method there. instead create the new client in your controller.

below i updated your classes to reflect the changes.

clientformrequest

class clientformrequest extends request {

    public function authorize()
    {
        return true;
    }


    public function rules()
    {

    }

    public function validator(array $data)
    {
        return validator::make($data, [
            'fullname' => 'required|max:255',
            'email' => 'required|email|max:255|unique:users',
        ]);
    }
}

registercontroller

class registercontroller extends controller {

    public function create()
    {
        return view('client.client');
    }

    public function store(clientformrequest $request)
    {       
        // clientformrequest was valid

        // create the client
        client::create([
            'fullname' => $request->input('fullname'),
            'email' => $request->input('email'),
        ]);

        return redirect::route('client.client')
        ->with('message', 'record inserted!');
    }

}

score:1

first of all, i would suggest you to watch laravel 5 fundamentals repeatedly since it is free. other series also give great information.

secondly, i would suggest you to use at least sublime text and some useful packages to be able to inspect the depth nested relations of system files (namespaces, interfaces, inheritance tree etc...). if you can't/might not, this friend will serve you anytime laravel api

third, afaik, laravel request is build onto the symfony' request component. since you are trying to overload one of its core function as non static, you are getting this error.

in addition, to be honest, i wouldn't put my user/client model creation logic into the requests. laravel provides an good example for this kind of misconception. in the app\services folder, you will find a registrar service for laravel oem user model.

let's inspect the problem with different cases.

but first, basic...

lets assume that all logic should be put inside the controller.

registercontroller.php

<?php namespace app\http\controllers;
use app\http\requests;
use app\http\controllers\controller;
use request;

class registercontroller extends controller {
    public function create()
    {
        return view('client.client');
    }

    public function store()
    {   
        $data = request::all(); //requested data via facade
        //prepare validatation
        $validation = validator::make($data, [ 
                'fullname' => 'required|max:255',
                'email' => 'required|email|max:255|unique:users',
                ]);
        //validate
        if ($validation->fails())
        {
            return redirect()->back()->witherrors($v->errors());
        }
        // create the client
        client::create([
            'fullname' => request::input('fullname'),
            'email'    => request::input('email'),
        ]);

        return \redirect::route('client.client')
        ->with('message', 'record inserted!');
    }

}

second solution

you might be willing to separate the validation logic and apply some dependency injection.

registercontroller.php

<?php namespace app\http\controllers;

use app\http\requests;
use app\http\controllers\controller;
use app\http\requests\clientformrequest;

class registercontroller extends controller {

    public function create()
    {
        return view('client.client');
    }

    public function store(clientformrequest $request)
    {   
        // create the client
        client::create([
            'fullname' => $request->input('fullname'),
            'email' => $request->input('email'),
        ]);

        return \redirect::route('client.client')
        ->with('message', 'record inserted!');
    }

}

clientformrequest.php

use stringy\create;

use app\user;
use validator;
use app\http\requests\clientformrequest;
class clientformrequest extends request {

    public function authorize()
    {
        return true;
    }


    public function rules()
    {
        return [
            'fullname' => 'required|max:255',
            'email' => 'required|email|max:255|unique:users'
        ];
    }

}

third solution

you might be willing to take things further and even separate the object creation logic as an service to use it anywhere. now your request file would stay the same. however,

registercontroller.php

use app\http\requests;
use app\http\controllers\controller;
use app\http\requests\clientformrequest;
use app\services\clientregistrar;

class registercontroller extends controller {

    private $registrar;

    public function __construct(clientregistrar $registrarservice)
    {
        $this->registrar = $registrarservice;
    }
    public function create()
    {
        return view('client.client');
    }

    public function store(clientformrequest $request)
    {   

        $newclient = $this->registrar->create($request->all());
        return \redirect::route('client.client')
        ->with('message', 'record inserted!')->compact('newclient');
    }

}

app\services\clientregistrar.php

 use app\client;
 use validator;
 use illuminate\contracts\auth\registrar as registrarcontract;

 class clientregistrar implements registrarcontract {

    /**
     * get a validator for an incoming registration request.
     *
     * @param  array  $data
     * @return \illuminate\contracts\validation\validator
     */
    public function validator(array $data)
    {
        return validator::make($data, [
           'fullname' => 'required|max:255',
        'email' => 'required|email|max:255|unique:users',
        ]);
    }

    /**
     * create a new client instance after a valid registration.
     *
     * @param  array  $data
     * @return client
     */
    public function create(array $data)
    {
        // create the client
        return client::create([
                'fullname' => $data['fullname'],
                'email' => $data['email'],
            ]);
    }

 }

to my conclusion there is no correct and best way to solve a problem. stay with the best applicable and appropriate way for you and your project scale.

you also might be interested in;

jeffrey way's laravel auto validate on save


Related Query

More Query from same tag