Please, what is the meaning of this error and how do i solve it. I tried to submit form and i get this error.
i have searched for other similar problems but i didnt get this type of error
Method Illuminate\Validation\Validator::validate{ouuowwd
i dont know how to go about it
namespace App\Http\Controllers;
class PropertyController extends Controller
{
public function index()
{
//
}
public function create()
{
return view('pages.uploadapartment', [
'states' => State::all(),
'areas' => Area::all(),
]);
}
public function store(Request $request)
{
$validatedData = $request->validate([
'building' => 'required',
'buildingtype' => 'required',
'flatbuildingtype' => 'nullable',
'buildingincompound' => 'required',
'firstfloor' => 'nullable',
'secondfloor'=> 'nullable',
'thirdfloor' => 'nullable',
'bedroom1' => 'image'|'nullable',
'kitchenpic' => 'image'|'nullable',
'bedroom2' => 'image'|'nullable',
'bedroom3' => 'image'|'nullable',
'bedroom4' => 'image'|'nullable',
'address' => 'string'|'required',
'area' => 'string'|'required',
'state'=> 'string'|'required',
'meetingplace'=> 'string'|'required'
]);
$apartment = Property::create([
'building' => $request-> building,
'FlatType' => $request->flatbuildingtype,
'firstfloor' => $request->firstfloor,
'secondfloor'=> $request->secondfloor,
'room3' => $request->bedroom3,
'kitchenpic' => $request->kitchenpic,
'compound' => $request->bedroom4,
]);
$apartment->save();
return redirect('/')->with('status', 'Your apartment for rent was successfully uploaded.');
}
Your syntax for the validation rules is wrong.
'bedroom1' => 'image'|'nullable',
'kitchenpic' => 'image'|'nullable',
'bedroom2' => 'image'|'nullable',
'bedroom3' => 'image'|'nullable',
'bedroom4' => 'image'|'nullable',
'address' => 'string'|'required',
'area' => 'string'|'required',
'state'=> 'string'|'required',
'meetingplace'=> 'string'|'required'
should be
'bedroom1' => 'image|nullable',
'kitchenpic' => 'image|nullable',
'bedroom2' => 'image|nullable',
'bedroom3' => 'image|nullable',
'bedroom4' => 'image|nullable',
'address' => 'string|required',
'area' => 'string|required',
'state'=> 'string|required',
'meetingplace'=> 'string|required'
or
'bedroom1' => ['image', 'nullable'],
'kitchenpic' => ['image', 'nullable'],
'bedroom2' => ['image', 'nullable'],
'bedroom3' => ['image', 'nullable'],
'bedroom4' => ['image', 'nullable'],
'address' => ['string', 'required'],
'area' => ['string', 'required'],
'state'=> ['string', 'required'],
'meetingplace'=> ['string', 'required'],
The weird error you're getting probably originates from this. You're using the bitwise OR operator on two strings. It made all your rules nonsense.
For example
'bedroom' => 'image'|'nullable'
evaluates to
'bedroom' => 'o}moeble'
Related
I have a registration form where I want to insert data where one field name is
Referrer_id. Now I want when the user register in if the referrer_id means the same id number appeared in more than two rows, it throws an error like. This referrer_id also reserved two times. I can't use the unique function here because two users can use one referrer_id.
This is my code:
Validation
protected function validator(array $data)
{
return Validator::make($data, [
'email' => 'required|string|email|max:255|unique:users',
'password' => 'required|string|min:6|confirmed',
'referrer_id' => 'required',
'position' => 'required',
'first_name' => ['required', 'regex:/^[A-ZÀÂÇÉÈÊËÎÏÔÛÙÜŸÑÆŒa-zàâçéèêëîïôûùüÿñæœ0-9_.,() ]+$/'],
'last_name' => ['required', 'regex:/^[A-ZÀÂÇÉÈÊËÎÏÔÛÙÜŸÑÆŒa-zàâçéèêëîïôûùüÿñæœ0-9_.,() ]+$/'],
'birth_day' => 'required',
'mobile' => 'required',
'street_address' => 'required',
'city' => ['required', 'regex:/^[A-ZÀÂÇÉÈÊËÎÏÔÛÙÜŸÑÆŒa-zàâçéèêëîïôûùüÿñæœ0-9_.,() ]+$/'],
'post_code' => 'required|numeric|min:0',
'country' => 'required',
'username' => 'required',
]);
}
And here is the Create user function :
protected function create(array $data)
{
$ref_id = $data['referrer_id'];
return User::create([
'email' => $data['email'],
'password' => bcrypt($data['password']),
'referrer_id' => $data['referrer_id'],
'position' => $data['position'],
'first_name' => $data['first_name'],
'last_name' => $data['last_name'],
'mobile' => $data['mobile'],
'street_address' => $data['street_address'],
'city' => $data['city'],
'post_code' => $data['post_code'],
'country' => $data['country'],
'username' => $data['username'],
'birth_day' => date('Y-m-d',strtotime($data['birth_day'])),
'join_date' => Carbon::today(),
'balance' => 0,
'status' => 1,
'paid_status' => 0,
'ver_status' => 0,
'ver_code' => $pin,
'forget_code' => 0,
'posid' => $posid,
'tauth' => 0,
'tfver' => 1,
'emailv' => 0,
'smsv' => 1,
]);
}
Please give me logic or any other code which I use in validation.
from my understanding two users can have thesame referral_id. i.e referring to the person who sponsor the two users. right? so to check if the referral_id is more that two, you can use count() to check like this (am using query buider):
//check if referral_id exists
if( $check = DB::table('table')->where('referral_id',$referral_id)->count() >0 )
{
if($check<3 )
{
//proceed to insert into DB
}
else if($check=2)
{
// display error
}
}
you can try the above piece by changing the values till you get the correct validation
First check counts of referrer_id.
protected function create(array $data)
{
$ref_id = $data['referrer_id'];
$count = User::where('referral_id',$ref_id)->count();
if($count<2){
return User::create([
'email' => $data['email'],
'password' => bcrypt($data['password']),
'referrer_id' => $data['referrer_id'],
'position' => $data['position'],
'first_name' => $data['first_name'],
'last_name' => $data['last_name'],
'mobile' => $data['mobile'],
'street_address' => $data['street_address'],
'city' => $data['city'],
'post_code' => $data['post_code'],
'country' => $data['country'],
'username' => $data['username'],
'birth_day' => date('Y-m-d',strtotime($data['birth_day'])),
'join_date' => Carbon::today(),
'balance' => 0,
'status' => 1,
'paid_status' => 0,
'ver_status' => 0,
'ver_code' => $pin,
'forget_code' => 0,
'posid' => $posid,
'tauth' => 0,
'tfver' => 1,
'emailv' => 0,
'smsv' => 1,
]);
}else{
// Display a message here
}
}
I am trying to submit a form data using Laravel controller. But I got this error while submit
local.ERROR: BadMethodCallException: Method [validateTextRequired] does not exist.
controller.php
$this->validate($request, [
'photo' => 'required|mimes:jpg,gif,png,jpe,jpeg',
'title' => 'required|min:3|max:45',
'name' => 'required',
'address' => 'required',
'city' => 'required',
'tribe' => 'required',
'language' => 'required',
'country' => 'required',
'student_id' => 'required',
'tribe_university_name' => 'required',
'student_program_of_study' => 'required',
'faculty' => 'required',
'bank_name' => 'required',
'account_number' => 'required',
'address' => 'required',
'swift_code' => 'required',
'routing_number' => 'required',
// 'categories_id' => 'required',
'goal' => 'required|integer|max:' . $this->settings->max_campaign_amount . '|min:' . $this->settings->min_campaign_amount,
'description' => 'text_required|required|min:20',
]);
if ($this->request->hasFile('photo')) {
$image = $request->photo->store('public/images');
}
$user = User::find(Auth::user()->id);
$user->address = trim($this->request->address);
$user->city = trim($this->request->city);
$user->tribe = trim($this->request->tribe);
$user->tribe_university_name = trim($this->request->tribe_university_name);
$user->student_program_of_study = trim($this->request->student_program_of_study);
$user->faculty = trim($this->request->faculty);
$user->level = trim($this->request->level);
$user->save();
return $id_campaign;
Can't solve the problem. Anybody help please ?
in laravel 5.6 app I have table name as vehicles, then I need update some of table values in VehicleController update function with validation as this,
$this->validate($request, [
'provincename' => 'required|min:3',
'districtname' => 'required',
'townname' => 'required',
'brandname' => 'required',
'modelname' => 'required',
'year' => 'required',
'condition' => 'required',
'milage' => 'required',
'data' => 'required',
'price' => 'required',
'telephone' => 'required',
'categoryname' => 'required',
'tramsmission' => 'required',
'fueltype' => 'required',
'enginecapacity' => 'required'
]);
and my update controller is like this,
$vehicle = Vehicle::find($id);
$vehicle->provincename = $request->input('provincename');
$vehicle->districtname = $request->input('districtname');
$vehicle->townname = $request->input('townname');
$vehicle->brandname = $request->input('brandname');
$vehicle->modelname = $request->input('modelname');
$vehicle->modelyear = $request->input('year');
$vehicle->condition = $request->input('condition');
$vehicle->milage = $request->input('milage');
$vehicle->detail = $request->input('data');
$vehicle->price = $request->input('price');
$vehicle->telephone = $request->input('telephone');
$vehicle->categoryname = $request->input('categoryname');
$vehicle->transmission = $request->input('transmission');
$vehicle->fueltype = $request->input('fueltype');
$vehicle->enginecapacity = $request->input('enginecapacity');
$vehicle->user_id = Auth::user()->id;
$vehicle->save();
My update is ok. it is working. but with controller validation it is not updating. without validation it is working. how can fix this? what is the problem with this?
try this kind of validation format:
$validatedData = $request->validate([
'provincename' => 'required|min:3',
'districtname' => 'required',
'townname' => 'required',
'brandname' => 'required',
'modelname' => 'required',
'year' => 'required',
'condition' => 'required',
'milage' => 'required',
'data' => 'required',
'price' => 'required',
'telephone' => 'required',
'categoryname' => 'required',
'tramsmission' => 'required',
'fueltype' => 'required',
'enginecapacity' => 'required'
]);
EDIT
don't forget to use the validator. Add use Validator; after the namespace.
So I have upload_media and url. upload_media is where you have to upload a .pdf file, and url if you want a url.
so what I want is that, if upload_media is not empty then, url should not be required. If the user decided to use the url, then the upload_media will not be required. But if either of them doesn't have a value then it should return a required error.
Here is my validation:
$this->validate($request, [
'title' => 'required',
'viewing_time' => 'required',
'tags' => '',
'description' => '',
'organization' => '',
'upload_media' => '',
'url' => '',
'upload_preview' => 'required|file|image'
]);
You can use required_without rule: https://laravel.com/docs/5.6/validation#rule-required-without
$this->validate($request, [
'title' => 'required',
'viewing_time' => 'required',
'tags' => '',
'description' => '',
'organization' => '',
'upload_media' => 'required_without:url',
'url' => 'required_without:upload_media',
'upload_preview' => 'required|file|image'
]);
$rules = [
'title' => 'required',
'viewing_time' => 'required',
'tags' => '',
'description' => '',
'organization' => '',
'upload_media' => 'required',
'url' => 'required',
'upload_preview' => 'required|file|image'
];
if ($request->file('upload_media')->isValid()) {
$rules['url'] = '';
} elseif (!empty($request->get('url'))) {
$rules['upload_media'] = '';
}
$this->validate($request, $rules);
I am writing Validator in Laravel, and so I am getting json format request.
I have written validate logic for main json's fields such as id, name... Now I have items array of objects in json, and I need to validate each item from this array which is passed.
Here's example of json request: https://api.myjson.com/bins/ob3lh
And here's my validator so far:
private function update()
{
return [
'id' => 'required',
'place_id' => 'required',
'place_table_id' => 'required',
'user_id' => 'required',
'seen' => 'required',
'state' => 'required',
'number' => 'required',
'date' => 'required',
'price' => 'required',
'table_number' => 'required',
'note' => 'required',
];
}
How can I add simply for example nested validator which will validate each of items object?
You can define nested validation rules like this:
private function update()
{
return [
'id' => 'required',
'place_id' => 'required',
'place_table_id' => 'required',
'user_id' => 'required',
'seen' => 'required',
'state' => 'required',
'number' => 'required',
'date' => 'required',
'price' => 'required',
'table_number' => 'required',
'note' => 'required',
'items' => 'required|array|min:1',
'items.*.id' => 'required',
'items.*.name' => 'required',
'items.*.amount' => 'required',
'items.*.price' => 'required',
];
}
You can find more info on this in the docs: https://laravel.com/docs/5.5/validation#validating-arrays