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;
Source: stackoverflow.com
Related Query
- Error on insert data into database using laravel5
- How to insert form data into GoogleCloud Mysql database using java
- How to insert data into Google Cloud mysql database using eclipse
- Command failed with error 8000 (AtlasError) when try to insert data into collection on Atlast server
- Inserting data into a database using servlet returns a blank page
- I can't retrieve data from MySQL database using a JSP file and receive a java.math.BigInteger cannot be cast to java.lang.Long error
- Insert data into SQLite Database Browser
- Insert data into MySQL from Excel via Eclipse using Selenium and Testng
- How to identify the dynamic content (from oracle database) and insert into database using radio button?
- How to read the data from mysql database and insert it into an implemented Hashtable?
- Inserting data using JSP (Eclipse) into database (XAMPP, MySQL)
- insert data into mysql database - java eclipse
- how to insert my html form data to my database using restfulwebservice in eclipse
- How to insert and retrieve data from database with Web Service in java using JAX - RS and tomcat in eclipse
- ERRORS [TRACE] [rpctest] - Finding entry point classes: using GWT to insert data into MySql using Hibernate
- c++ : Create database using SQLite for Insert & update
- How to retrieve data from database using webservices (JAX - RS) in eclipse using Java
- Collect into a HashSet using Java8 stream over a set gives `Type Mismatch` Error
- Big error about data type not supported in JAX-RPC specification using Eclipse
- DateTime is not inserting into the database using jsp
- Program run from eclipse is able to insert data into Mongo DB of local machine but not into Mongo DB of remote machine
- insert and receive the data from MySQL through Android using PHP
- importing a csv file into oracle database using java
- Error importing cxf projects into eclipse using m2e: Couldn't find that class org.apache.cxf.pmd.UnsafeStringConstructorRule
- Eclipse data not inserting into SQLite Database and crashing
- Textbox value from JSP is unable to insert into the database
- No error , no output and data is not inserted in database in jsp
- Data truncation error using mysql jdbc when inserting data from csv file to table
- Cannot insert items into dynamodb through a lambda function using java eclipse
- Generate insert statements from database using Eclipse/STS
More Query from same tag
- Mac Eclipse not resolving C++ lib functions in NDK
- Eclipse : does it sometimes cause an error even though it has not an issue with code?
- Compatibility issue between the 'groovy-all' jars present in eclipse plugin and maven dependency
- Can't install EGit in Eclipse
- Commit Folder From Local Directory to Online Using SVN
- Unstable behavior of a library (UnsatisfiedLinkError) in Eclipse/Gradle multi-projects
- Eclipse 3.6: Can't find Git support
- Errors on @NamedQuery elements straight from repository
- Groovy Grails Tools Suit (GGTS) Maven plugin
- android sdk manager not updating
- Is there a way to change the text of an Action Bar Menu Item when I touch the menu item in Android?
- Why doesn't Android appear in Eclipses' preferences?
- Getting error The method sort(List<T>) in the type Collections is not applicable for the arguments (List<LinkedInUser>)
- How to add source of 'Android Private Libraries' to ADT eclipse?
- Duplicate variable in eclipse debugger
- How to open a website using eclipse
- How do you configure an environment for an open source project from sourceforge
- deleting jars from ivy resolved libraries
- ADT Bundle Fails to Create New Activities
- How to import JUnit 5 source to Eclipse?
- Eclipse builds very slow
- Eclipse XLRD, XLWT Import Error
- Import file from SVN to android project in eclipse
- Eclipse Luna on Windows with C/C++ and SDL 2
- Shortcuts for Mac Users: Eclipse
- IDE or addons for IDE that support W3C WAI
- How to compare a file in a project with one in the filesystem in eclipse?
- Maven Assembly Plugin NoClassDefFoundError
- Java ArrayList in forLoop out of bounds
- Eclipse Plugin - How do I create all folders (IFolders) in a given path (IPath)