I am learning laravel livewire, and this is my first time using livewire.
I am having trouble running my code on Laravel 8 with laravel-livewire. When I click submit always showing an error like that.
I'm don't know what's wrong and how to fix this
web.php
<?php
use Illuminate\Support\Facades\Route;
use App\Http\Livewire\Product;
Route::get('/products', Product::class);
Controller
<?php
namespace App\Http\Livewire;
use Livewire\Component;
use Livewire\WithFileUploads;
use App\Models\Product as ProductModel;
use Illuminate\Support\Facades\Storage;
class Product extends Component
{
use WithFileUploads;
public $name, $image, $description, $qty, $price;
public function previewImage()
{
$this->validate([
'image' => 'image|max:2048'
]);
}
public function store()
{
$this->validate([
'name' => 'required',
'image' => 'image|max:2048|required',
'description' => 'required',
'qty' => 'required',
'price' => 'required',
]);
$imageName = md5($this->image.microtime().'.'. $this->extension());
Storage::putFileAs(
'public/images',
$this->image,
$imageName
);
ProductModel::create([
'name' => $this->name,
'image' => $imageName,
'description' => $this->description,
'qty' => $this->qty,
'price' => $this->price
]);
session()->flash('info', 'Product created sSccessfully');
$this->name = '';
$this->image = '';
$this->description = '';
$this->qty = '';
$this->price = '';
}
}
In this is my blade code, i hope someone can help me. Thanks
<div>
<div class="row">
<div class="col-md-8">
<div class="card">
<div class="card-body">
<h2 class="font-weight-bold mb-3">Product List</h2>
<table class="table table-bordered table-hover table-striped">
<thead>
<tr>
<th>No</th>
<th>Name</th>
<th>Image</th>
<th>Description</th>
<th>Qty</th>
<th>Price</th>
</tr>
</thead>
<tbody>
#foreach($products as $index=>$product)
<tr>
<td>{{ $index+1 }}</td>
<td>{{ $product->name }}</td>
<td>{{ $product->image }}</td>
<td>{{ $product->description }}</td>
<td>{{ $product->qty }}</td>
<td>{{ $product->price }}</td>
</tr>
#endforeach
</tbody>
</table>
</div>
</div>
</div>
<div class="col-md-4">
<div class="card">
<div class="card-body">
<h2 class="font-weight-bold mb-3">Create Product</h2>
<form wire:submit.prevent="store">
<div class="form-group">
<label>Product Name</label>
<input wire:model="name" type="text" class="form-control">
#error('name') <small class="text-danger">{{ $message }}</small> #enderror
</div>
<div class="form-group">
<label>Product Image</label>
<div class="custom-file">
<input wire:model="image" type="file" class="custom-file-input" id="customFile">
<label for="customFile" class="custom-file-label">Choose Image</label>
</div>
#error('image') <small class="text-danger">{{ $message }}</small> #enderror
</div>
#if($image)
<label class="mt-2">Image Preview</label>
<img src="{{ $image->temporaryUrl() }}" class="img-fluid" alt="Preview Image">
#endif
<div class="form-group">
<label>Description</label>
<textarea wire:model="description" class="form-control"></textarea>
#error('description') <small class="text-danger">{{ $message }}</small> #enderror
</div>
<div class="form-group">
<label>Qty</label>
<input wire:model="qty" type="number" class="form-control">
#error('qty') <small class="text-danger">{{ $message }}</small> #enderror
</div>
<div class="form-group">
<label>Price</label>
<input wire:model="price" type="number" class="form-control">
#error('price') <small class="text-danger">{{ $message }}</small> #enderror
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary btn-block">Submit Product</button>
</div>
</form>
</div>
</div>
<div class="card mt-3">
<div class="card-body">
<h3>{{ $name }}</h3>
<h3>{{ $image }}</h3>
<h3>{{ $description }}</h3>
<h3>{{ $qty }}</h3>
<h3>{{ $price }}</h3>
</div>
</div>
</div>
</div>
use $this->image->extension() or \File::extension($this->image);
instead of $this->extensionin your code
$imageName = md5($this->image.microtime().'.'. $this->extension());
extension() is a method of FIle class thus needs a instance of Symfony\Component\HttpFoundation\File\UploadedFile class
Laravel required if validation issue
Blade:
{{ Form::open(['route' => ['updateEmailSettings']]) }}
<div class="form-group row">
{{ Form::label('driver','Mail Driver',['class' => 'col-md-3 col-form-label required']) }}
<div class="col-md-9">
{{ Form::select('driver',$drivers, null,['class' => 'form-control', 'placeholder' => 'Select']) }}
</div>
</div>
<div class="form-group row">
<label class="col-md-3 col-form-label font-weight-bold">Mandrill</label>
</div>
<div class="form-group row">
{{ Form::label('mailgun_secret','Secret',['class' => 'col-md-3 col-form-label']) }}
<div class="col-md-9">
{{ Form::text('mailgun["secret"]',null,['class' => 'form-control', 'id' => 'mailgun_secret']) }}
</div>
</div>
<div class="form-group row">
<div class="col-md-9 ml-md-auto">
{{ Form::button('<i class="far fa-save"></i> Save',['class'=>'btn btn-primary mr-3','type'=>'submit']) }}
<a class="btn btn-danger" href="{{ route('emailSettings') }}"><i class="far fa-times-circle"></i> Cancel</a>
</div>
</div>
{{ Form::close() }}
Form Request:
return [
'driver' => 'required',
'mailgun.*.domain' => 'required_if:driver,mailgun'
];
Validation always fails. Please suggest me if i miss anything.
Resolved myself
Blade: Removed double quotes inside the bracket.
{{ Form::text('mailgun[secret]',null,['class' => 'form-control', 'id' => 'mailgun_secret']) }}
Form Request: Removed asterisk
'mailgun.domain' => 'required_if:driver,mailgun'
I have controller where I save invoice, but it is option to add item, bank and company. When I want to save the item and return to the invoice view, there is a problem:
TokenMismatchException
in VerifyCsrfToken.php (line 68)
or I refresh page I get an error: HttpException
This is my controller:
public function create()
{
$banks = Bank::all();
$methods = Payment_method::pluck('name_payment', 'id');
$users = User::pluck('name', 'id');
$items = Item::all();
$vats = Vat::all();
$companies = Company::all('name', 'id');
$numberProform = $this->setNumberProform();
if (isset($_COOKIE["addInvoiceForm"])) {
$previousData = $_COOKIE["addInvoiceForm"];
$previousData = unserialize($previousData);
return view('invoice.addInvoice', compact('items', 'companies', 'users', 'vats', 'numberProform', 'methods', 'banks', 'previousData'));
}
return view('invoice.addInvoice', compact('items', 'companies', 'users', 'vats', 'numberProform', 'methods', 'banks'));
}
public function store(Request $request)
{
if ($request->add === 'item') {
setcookie('addInvoiceForm', serialize($request->input()), time() + (86400 * 30), "/");
return redirect('addItem');
}
$this->validation($request);
$input = Req::all();
$invoice = Invoice::create($input);
$i = 1;
while ($request->has('item_' . $i)) {
$invoice->items()->attach([$request->{'item_' . $i} => ['quantity' => $request->{'quantity_' . $i}]]);
$i++;
}
return redirect('listInvoice');
}
view addInvoice.blade.php:
#extends('layouts.app')
#section('content')
<div class="container">
<div class="row">
<div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1 col-sm-12 col-sm-offset-0">
<div class="panel panel-default">
{!! Form::open(['url' => 'saveInvoice', 'method' => 'post', 'class' => 'form-horizontal']) !!}
{{ csrf_field() }}
<div class="panel-heading">
<h2>Proforma nr {{$numberProform}}</h2>
</div>
<div class="form-group">
<div class="col-sm-12">
{!! Form::hidden('number', $numberProform) !!}
<span>UWAGA: PRO FORMA nie jest dokumentem księgowym i nie jest podstawą do odliczenia VAT.</span>
</div>
</div>
<div class="panel-body">
<div class="form-horizontal">
<div class="row">
{!! Form::hidden('proforma', "1") !!}
{!! Form::hidden('user_id', \Illuminate\Support\Facades\Auth::user()->getAuthIdentifier()) !!}
<div class="form-group {{ $errors->has('place_issue') ? ' has-error' : '' }}">
<div class="col-sm-4 control-label">
{!! Form::label('place_issue', 'Miejsce:') !!}
</div>
<div class="col-sm-6">
{!! Form::text('place_issue', $previousData['place_issue'], ['class' => 'form-control']) !!}
#if ($errors->has('place_issue'))
<span class="help-block"><strong>{{ $errors->first('place_issue') }} </strong></span>
#endif
</div>
</div>
<div class="form-group {{ $errors->has('date_issue') ? ' has-error' : '' }}">
<div class="col-sm-4 control-label">
{!! Form::label('date_issue', 'Data wystawienia:') !!}
</div>
<div class="col-sm-6">
{!! Form::date('date_issue', $previousData['date_issue'], ['class' => 'form-control']) !!}
#if ($errors->has('date_issue'))
<span class="help-block"><strong>{{ $errors->first('date_issue') }} </strong></span>
#endif
</div>
</div>
<div class="form-group{{ $errors->has('date_payment') ? ' has-error' : '' }}">
<div class="col-sm-4 control-label">
{!! Form::label('date_payment', 'Zapłata do:') !!}
</div>
<div class="col-sm-6">
{!! Form::date('date_payment', $previousData['date_payment'], ['class' => 'form-control']) !!}
#if ($errors->has('date_payment'))
<span class="help-block"><strong>{{ $errors->first('date_payment') }} </strong></span>
#endif
</div>
</div>
<div class="form-group {{ $errors->has('description') ? ' has-error' : '' }}">
<div class="col-sm-4 control-label">
{!! Form::label('description', 'Opis:') !!}
</div>
<div class="col-sm-6">
{!! Form::text('description', $previousData['description'], ['class' => 'form-control']) !!}
#if ($errors->has('description'))
<span class="help-block"><strong>{{ $errors->first('description') }} </strong></span>
#endif
</div>
</div>
{{------------FIRMA------------}}
<div class="form-group {{ $errors->has('company_id') ? ' has-error' : '' }}">
<div class="col-sm-4 control-label">
<label for="company_id">Nazwa firmy</label>
</div>
<div class="col-sm-6">
<select name="company_id" id="company_id" class="form-control">
#foreach($companies as $company)
<option
value="{{$company->id }}" {{ $company->id==$previousData['company_id'] ? 'selected' : '' }}>
{{ $company->name }}
</option>
#endforeach
</select>
#if ($errors->has('company_id'))
<span class="help-block"><strong>{{ $errors->first('company_id') }} </strong></span>
#endif
</div>
<div class="col-sm-2">
<a href="{{ url('addCompany') }}" class="btn btn-success">
<span class="glyphicon glyphicon-plus"></span>
</a>
</div>
</div>
<div class="form-group">
<div class="col-sm-4 control-label">
{!! Form::label('bank_id', 'Bank:') !!}
</div>
<div class="col-sm-6">
<select class="form-control control-label" name="bank_id">
#foreach($banks as $bank)
<option value="{{$bank->id}}" {{ $bank->id==$previousData['bank_id']?'selected':''}}>
{{$bank->label}} ({{$bank->number_bank}});
</option>
#endforeach
</select>
</div>
<div class="col-sm-2">
<a href="{{ url('addBank') }}" class="btn btn-success">
<span class="glyphicon glyphicon-plus"></span>
</a>
</div>
</div>
<div class="form-group {{ $errors->has('item_id') ? ' has-error' : '' }}">
<div class="col-sm-4 control-label">
{!! Form::label('item_1_id', 'Dodaj przedmioty:') !!}
</div>
<div class="col-sm-6">
<select class="form-control control-label search-item">
#foreach($items as $item)
<option value="{{$item->id}}">
{{$item->name}}
</option>
#endforeach
</select>
</div>
<div class="col-sm-2">
<button type="submit" name="add" value="item" href="{{ url('addItem') }}" class="btn btn-success">
<span class="glyphicon glyphicon-plus"></span>
</button>
</div>
</div>
<div class="col-sm-12">
<div class="items-table-wr">
<table class="table table-hover items-table">
<tr>
<th>nazwa</th>
<th>vat</th>
<th>jednostka</th>
<th>cena netto</th>
<th>cena brutto</th>
<th>ilość</th>
<th>suma</th>
<th></th>
</tr>
<tbody class="items-list">
</tbody>
</table>
</div>
</div>
<div class="form-group {{ $errors->has('payment_method_id') ? ' has-error' : '' }}">
<div class="col-sm-4 control-label">
{!! Form::label('payment_method_id', 'Metoda płatności:') !!}
</div>
<div class="col-sm-6">
{!! Form::select('payment_method_id', $methods, ['class' => 'form-control']) !!}
#if ($errors->has('payment_method_id'))
<span class="help-block"><strong>{{ $errors->first('payment_method_id') }} </strong></span>
#endif
</div>
</div>
<div class="form-group">
<div class="col-sm-6 col-sm-offset-4 text-right">
<button type="submit" class="btn btn-primary">Zapisz proformę
<span class="glyphicon glyphicon-ok"></span></button>
</div>
</div>
{{--<pre>--}}
{{-- {{print_r($previousData)}}--}}
{{--</pre>--}}
{!! Form::close() !!}
</div>
</div>
</div>
</div>
</div>
</div>
</div>
#endsection
I add that the form is csrf token ({{csrf_field() }}).
I have no idea what it is, someone can help me? :)
I am trying to Update user Profile after they Login, It works well and says PROFILE UPDATED SUCCESSFULLY but nothing inserted on the Database Table, so in essence, the View shows nothing of the Updated form fields. Please anyone with an idea of where i am getting this wrong will be highly appreciated, Thanks.
CONTROLLER Update FUNCTION
public function update(Request $request)
{
$rules = [
'name' => 'required',
'email' => 'required',
'phone' => 'required|numeric',
'country' => 'required',
'gender' => 'required',
'birthday' => 'required',
'fb' => 'url',
'twitter' => 'url',
'gp' => 'url',
'instagram' => 'url',
'personal_site' => 'url',
'aboutme' => 'url',
'linkedin' => 'url',
'pinterest' => 'url'
];
$data= $request->all();
$validator = Validator::make($data, $rules);
if($validator->fails()){
return Redirect::back()->withInput()->withErrors($validator);
}
$user = Auth::user();
$user->name = $data['name'];
$user->email = $data['email'];
$user->phone = $data['phone'];
$user->country = $data['country'];
$user->birthday = $data['birthday'];
$user->address = $data['address'];
if($user->save()) {
$profile_id = $user->id;
$profile = Profile::find($profile_id);
if(count($profile) > 0) {
$profile->gender = $data['gender'];
$profile->city = $data['city'];
$profile->state = $data['state'];
$profile->aboutmyself = $data['aboutmyself'];
$profile->fb = $data['fb'];
$profile->twitter = $data['twitter'];
$profile->gp = $data['gp'];
$profile->instagram = $data['instagram'];
$profile->personal_site = $data['personal_site'];
$profile->aboutme = $data['aboutme'];
$profile->linkedin = $data['linkedin'];
$profile->pinterest = $data['pinterest'];
// $profile = $user->profile()->save($profile);
$profile->save();
}
} else {
return redirect()->back()->withInput()->withInfo("Something went wrong. Please, try again");
}
return redirect()->route('profile')->withSuccess("Your Profile Successfully Updated.");
}
MY VIEW (profile-edit.blade.php)
<div class="form-group row">
{!! Form::model($user, array('route' => 'post.edit.profile', 'method' => 'post', 'class' => 'form-horizontal')) !!}
{!! Form::label('name', "Full Name", array('class' => 'col-sm-3 control-label')) !!}
<div class="col-sm-8">
<div class="row">
<div class="col-md-9">
{!! Form::text('name', null, array('class' => 'form-control', 'placeholder' => 'Your Full Name', 'required' => 'required')) !!}
</div>
</div>
</div>
</div>
<div class="form-group row">
{!! Form::label('email', "Email Address", array('class' => 'col-sm-3 control-label')) !!}
<div class="col-sm-6 col-md-6">
<div class="input-group">
<span class="input-group-addon" id="basic-addon1">
<i class="material-icons md-18 text-muted">mail</i>
</span>
{!! Form::email('email', null, array('class' => 'form-control', 'placeholder' => '', 'required' => 'required')) !!}
</div>
</div>
</div>
<div class="form-group row">
{!! Form::label('phone', "Phone Number", array('class' => 'col-sm-3 control-label')) !!}
<div class="col-sm-6 col-md-6">
<div class="input-group">
<span class="input-group-addon" id="basic-addon1">
<i class="material-icons md-18 text-muted">mail</i>
</span>
{!! Form::text('phone', null, array('class' => 'form-control', 'placeholder' => 'e.g. +8801711223344', 'required' => 'required')) !!}
</div>
</div>
</div>
<div class="form-group row">
{!! Form::label('gender', "Gender", array('class' => 'col-sm-3 control-label')) !!}
<div class="col-sm-6 col-md-4">
{!! Form::select('gender', $gender, array('class' => 'c-select form-control', 'id' => '', 'required' => 'required')) !!}
</div>
</div>
<div class="form-group row">
{!! Form::label('birthday', "Birthday", array('class' => 'col-sm-3 control-label')) !!}
<div class="col-sm-6 col-md-4">
<div class="input-group">
<span class="input-group-addon" id="basic-addon2">
<i class="material-icons md-18 text-muted">language</i>
</span>
{!! Form::text('birthday', null, array('class' => 'datepicker form-control', 'placeholder' => '01/28/2016','id' => 'birthday', 'required' => 'required')) !!}
</div>
</div>
</div>
<div class="form-group row">
{!! Form::label('address', "Address", array('class' => 'col-sm-3 control-label')) !!}
<div class="col-sm-6 col-md-4">
<div class="input-group">
<span class="input-group-addon" id="basic-addon2">
<i class="material-icons md-18 text-muted">language</i>
</span>
{!! Form::text('address', null, array('class' => 'form-control', 'placeholder' => 'Street No., Area...','id' => 'address', 'required' => 'required')) !!}
</div>
</div>
</div>
<div class="form-group row">
{!! Form::label('city', "City", array('class' => 'col-sm-3 control-label')) !!}
<div class="col-sm-6 col-md-4">
<div class="input-group">
<span class="input-group-addon" id="basic-addon2">
<i class="material-icons md-18 text-muted">language</i>
</span>
{!! Form::text('city', $user->profile->city, array('class' => 'form-control', 'placeholder' => 'City', 'required' => 'required')) !!}
</div>
</div>
</div>
<div class="form-group row">
{!! Form::label('state', "State", array('class' => 'col-sm-3 control-label')) !!}
<div class="col-sm-6 col-md-4">
<div class="input-group">
<span class="input-group-addon" id="basic-addon2">
<i class="material-icons md-18 text-muted">language</i>
</span>
{!! Form::text('state', $user->profile->state, array('class' => 'form-control', 'placeholder' => 'State', 'required' => 'required')) !!}
</div>
</div>
</div>
<div class="form-group row">
{!! Form::label('country', "Country", array('class' => 'col-sm-3 control-label')) !!}
<div class="col-sm-8">
<div class="row">
<div class="col-md-6">
{!! Form::text('country', null, array('class' => 'form-control', 'placeholder' => 'Country','id' => '')) !!}
</div>
</div>
</div>
</div>
<div class="form-group row">
{!! Form::label('aboutmyself', "About Me", array('class' => 'col-sm-3 control-label')) !!}
<div class="col-sm-6 col-md-4">
<div class="input-group">
<span class="input-group-addon" id="basic-addon2">
<i class="material-icons md-18 text-muted">language</i>
</span>
{!! Form::textarea('aboutmyself', Auth::user()->profile->aboutmyself, array('class' => 'form-control', 'rows' => 4, 'placeholder' => 'About Yourself')) !!}
</div>
</div>
</div>
<div class="form-group row">
{!! Form::label('fb', "Facebook Link", array('class' => 'col-sm-3 control-label')) !!}
<div class="col-sm-6 col-md-4">
<div class="input-group">
<span class="input-group-addon" id="basic-addon2">
<i class="material-icons md-18 text-muted">language</i>
</span>
{!! Form::text('fb', $user->profile->fb, array('class' => 'form-control', 'placeholder' => 'https://facebook.com/username')) !!}
</div>
</div>
</div>
<div class="form-group row">
{!! Form::label('twitter', "Twitter Link", array('class' => 'col-sm-3 control-label')) !!}
<div class="col-sm-6 col-md-4">
<div class="input-group">
<span class="input-group-addon" id="basic-addon2">
<i class="material-icons md-18 text-muted">language</i>
</span>
{!! Form::text('twitter', $user->profile->twitter, array('class' => 'form-control', 'placeholder' => 'https://twitter.com/username')) !!}
</div>
</div>
</div>
<div class="form-group row">
{!! Form::label('gp', "Google+ Link", array('class' => 'col-sm-3 control-label')) !!}
<div class="col-sm-6 col-md-4">
<div class="input-group">
<span class="input-group-addon" id="basic-addon2">
<i class="material-icons md-18 text-muted">language</i>
</span>
{!! Form::text('gp', $user->profile->gp, array('class' => 'form-control', 'placeholder' => 'https://plus.google.com/+username')) !!}
</div>
</div>
</div>
<div class="form-group row">
{!! Form::label('personal_site', "Personal Site", array('class' => 'col-sm-3 control-label')) !!}
<div class="col-sm-6 col-md-4">
<div class="input-group">
<span class="input-group-addon" id="basic-addon2">
<i class="material-icons md-18 text-muted">language</i>
</span>
{!! Form::text('personal_site', $user->profile->personal_site, array('class' => 'form-control', 'placeholder' => 'http://www.mywebsite.me')) !!}
</div>
</div>
</div>
<div class="form-group row">
{!! Form::label('instagram', "Instagram Link", array('class' => 'col-sm-3 control-label')) !!}
<div class="col-sm-6 col-md-4">
<div class="input-group">
<span class="input-group-addon" id="basic-addon2">
<i class="material-icons md-18 text-muted">language</i>
</span>
{!! Form::text('instagram', $user->profile->instagram, array('class' => 'form-control', 'placeholder' => 'https://www.instagram.com/username')) !!}
</div>
</div>
</div>
<div class="form-group row">
{!! Form::label('linkedin', "LinkedIn Link", array('class' => 'col-sm-3 control-label')) !!}
<div class="col-sm-6 col-md-4">
<div class="input-group">
<span class="input-group-addon" id="basic-addon2">
<i class="material-icons md-18 text-muted">language</i>
</span>
{!! Form::text('linkedin', $user->profile->linkedin, array('class' => 'form-control', 'placeholder' => 'https://www.linkedin.com/username')) !!}
</div>
</div>
</div>
<div class="form-group row">
{!! Form::label('pinterest', "Pinterest Link", array('class' => 'col-sm-3 control-label')) !!}
<div class="col-sm-6 col-md-4">
<div class="input-group">
<span class="input-group-addon" id="basic-addon2">
<i class="material-icons md-18 text-muted">language</i>
</span>
{!! Form::text('pinterest', $user->profile->pinterest, array('class' => 'form-control', 'placeholder' => 'https://www.pinterest.com/username')) !!}
</div>
</div>
</div>
<!-- <div class="form-group row">
<label for="password" class="col-sm-3 form-control-label">Change Password</label>
<div class="col-sm-6 col-md-4">
<div class="input-group">
<span class="input-group-addon" id="basic-addon3">
<i class="material-icons md-18 text-muted">lock</i>
</span>
<input type="text" class="form-control" placeholder="Enter new password">
</div>
</div>
</div> -->
<div class="form-group row">
<div class="col-sm-8 col-sm-offset-3">
<div class="media">
<div class="media-left">
{!! Form::submit('Save Changes', array('class' => 'btn btn-success')) !!}
</div>
<!-- <div class="media-body media-middle p-l-1">
<label class="c-input c-checkbox">
<input type="checkbox" checked>
<span class="c-indicator"></span> Subscribe to Newsletter
</label>
</div> -->
</div>
</div>
</div>
{!! Form::close() !!}
User MODEL (User.php)
<?php
namespace App;
use Illuminate\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Foundation\Auth\Access\Authorizable;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
use Zizaco\Entrust\Traits\EntrustUserTrait;
class User extends Model implements AuthenticatableContract,
AuthorizableContract,
CanResetPasswordContract
{
use Authenticatable, Authorizable, CanResetPassword,EntrustUserTrait {
EntrustUserTrait::can as may;
Authorizable::can insteadof EntrustUserTrait;
}
/**
* The database table used by the model.
*
* #var string
*/
protected $table = 'users';
/**
* The attributes that are mass assignable.
*
* #var array
*/
protected $fillable = ['name', 'email', 'password'];
/**
* The attributes excluded from the model's JSON form.
*
* #var array
*/
protected $hidden = ['password', 'remember_token'];
public function profile(){
return $this->hasOne('App\Profile','user_id','id');
}
public function pending(){
return $this->hasMany('App\PendingTransfers', 'user_id', 'id');
}
public function transaction(){
return $this->hasMany('App\Transaction', 'user_id', 'id');
}
}
ROUTE
Route::group(array('middleware' => 'auth'), function()
{
Route::get('logout', ['as' => 'logout', 'uses' => 'Auth\AuthController#logout']);
Route::get('profile', ['as' => 'profile', 'uses' => 'UsersController#profile']);
Route::get('edit-profile', ['as' => 'edit.profile', 'uses' => 'UsersController#edit']);
Route::post('edit-profile', ['as' => 'post.edit.profile', 'uses' => 'UsersController#update']);
Route::post('edit-photo', ['as' => 'post.edit.photo', 'uses' => 'UsersController#photoUpdate']);
Route::get('dashboard', array('as' => 'dashboard', 'uses' => 'Auth\AuthController#dashboard'));
Route::get('change-password', array('as' => 'password.change', 'uses' => 'Auth\AuthController#changePassword'));
Route::post('change-password', array('as' => 'password.doChange', 'uses' => 'Auth\AuthController#doChangePassword'));
UPDATE: Thanks for the Prompt response but that didn't fix it though, Am thinking the Fault might be from the CONTROLLER FUNCTION at this point:
if($user->save()) {
$profile_id = $user->id;
$profile = Profile::find($profile_id);
if(count($profile) > 0) {
$profile->gender = $data['gender'];
$profile->city = $data['city'];
$profile->state = $data['state'];
$profile->aboutmyself = $data['aboutmyself'];
$profile->fb = $data['fb'];
$profile->twitter = $data['twitter'];
$profile->gp = $data['gp'];
$profile->instagram = $data['instagram'];
$profile->personal_site = $data['personal_site'];
$profile->aboutme = $data['aboutme'];
$profile->linkedin = $data['linkedin'];
$profile->pinterest = $data['pinterest'];
// $profile = $user->profile()->save($profile);
$profile->save();
OR Probably from the VIEW Opening Form route/variable $user
{!! Form::model($user, array('route' => 'post.edit.profile', 'method' => 'post', 'class' => 'form-horizontal')) !!}
In User Model set all tables fields $fillable
protected $fillable = ['name', 'email', 'password','phone','country','gender'];
My laravel project not validate all fileds of my register form
Url: http://themovingpixel.com/myfinancialgoals/register
My resources/views/auth/register.blade.php code is here
#extends('layouts.register')
#section('content')
<div class="stage_top_bg">Financial Advisors Register</div>
<div class="container">
<div class="financial_mid_box">
<form name="myform" action="{{ url('/register') }}" method="POST">
{{ csrf_field() }}
<div class="stage_box">
<div class="stage_one_box stage_active steps">Stage 1</div>
<div class="stage_two_box steps">Stage 2</div>
<div class="stage_three_box steps">Stage 3</div>
<div class="stage_four_box steps">Stage 4</div>
</div>
<div class="financial_form_box formone">
<div class="col-lg-6 col-md-6">
<div class="financial_fild_main_box"> <span class="name_text">Name</span>
<div class="name_fild">
<input name="name" class="name_main_fild" type="text" placeholder="Name">
</div>
#if ($errors->has('name'))
<span class="help-block"><strong>{{ $errors->first('name') }}</strong></span>
#endif
</div>
</div>
<div class="col-lg-6 col-md-6">
<div class="financial_fild_main_box"> <span class="name_text">Practice</span>
<div class="name_fild">
<input name="practice" class="name_main_fild" type="text" placeholder="Practice">
</div>
#if ($errors->has('practice'))
<span class="help-block"><strong>{{ $errors->first('practice') }}</strong></span>
#endif
</div>
</div>
<div class="col-lg-6 col-md-6">
<div class="financial_fild_main_box"> <span class="name_text">Phone</span>
<div class="name_fild">
<input name="phone_number" class="name_main_fild" type="tel" placeholder="Phone">
</div>
#if ($errors->has('phone_number'))
<span class="help-block"><strong>{{ $errors->first('phone_number') }}</strong></span>
#endif
</div>
</div>
<div class="col-lg-6 col-md-6">
<div class="financial_fild_main_box"> <span class="name_text">Email</span>
<div class="name_fild">
<input name="email" class="name_main_fild" type="text" placeholder="Email">
</div>
#if ($errors->has('email'))
<span class="help-block"><strong>{{ $errors->first('email') }}</strong></span>
#endif
</div>
</div>
<div class="col-lg-6 col-md-6">
<div class="financial_fild_main_box"> <span class="name_text">Password</span>
<div class="name_fild">
<input name="password" class="name_main_fild" type="password" placeholder="Password">
</div>
</div>
</div>
<div class="clearfix"></div>
<div class="procced_button">Proceed</div>
</div>
<div class="financial_form_box stepsone">
<div class="col-lg-6 col-md-6">
<div class="financial_fild_main_box"> <span class="name_text">Package</span>
<div class="name_fild">
<select name="packages" class="name_main_fild">
<option value="0">Select</option>
<option value="45">$45/month</option>
<option value="60">$60/month</option>
</select>
</div>
</div>
</div>
<div class="clearfix"></div>
<div class="procced_button btns">Proceed</div>
</div>
<div class="financial_form_box steptwo">
<div class="financial_fild_main_box"> <span class="name_text">Payment</span>
<div class="payament_box"> <!-- <a href="#">
<div class="payament_icon"><img src="{{ asset('assets/frontend/images/payaple_icon.jpg')}}" alt="icon"></div>
</a> <a href="#">
<div class="payament_icon"><img src="{{ asset('assets/frontend/images/ebay_icon.jpg')}}" alt="icon"></div>
</a> <a href="#">
<div class="payament_icon"><img src="{{ asset('assets/frontend/images/pay_icon_three.jpg')}}" alt="icon"></div>
</a> <a href="#">
<div class="payament_icon"><img src="{{ asset('assets/frontend/images/pay_icon_four.jpg')}}" alt="icon"></div>
</a> <a href="#">
<div class="payament_icon"><img src="{{ asset('assets/frontend/images/pay_icon_six.jpg')}}" alt="icon"></div>
</a> <a href="#">
<div class="payament_icon"><img src="{{ asset('assets/frontend/images/pay_icon_seven.jpg')}}" alt="icon"></div>
</a> <a href="#">
<div class="payament_icon"><img src="{{ asset('assets/frontend/images/pay_icon_eight.jpg')}}" alt="icon"></div>
</a> -->
<div class="name_fild">
<select name="payment_type" class="name_main_fild">
<option value="0">Select</option>
<option value="paypal">Paypal</option>
<option value="ebay">Ebay</option>
<option value="cirrus">Cirrus</option>
<option value="visa">Visa</option>
<option value="discover">Discover</option>
<option value="google">Google</option>
<option value="eway">Eway</option>
</select>
</div>
</div>
</div>
<div class="clearfix"></div>
<div class="procced_button"><button type="submit" class="process_btn">Proceed</button></div>
</div>
</form>
</div>
</div>
#endsection
And my app/Http/Controllers/Auth code is here
<?php
namespace App\Http\Controllers\Auth;
use App\User;
use App\Userinfo;
use Validator;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ThrottlesLogins;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;
class AuthController extends Controller
{
/*
|--------------------------------------------------------------------------
| Registration & Login Controller
|--------------------------------------------------------------------------
|
| This controller handles the registration of new users, as well as the
| authentication of existing users. By default, this controller uses
| a simple trait to add these behaviors. Why don't you explore it?
|
*/
use AuthenticatesAndRegistersUsers, ThrottlesLogins;
/**
* Where to redirect users after login / registration.
*
* #var string
*/
protected $redirectTo = '/profile';
/**
* Create a new authentication controller instance.
*
* #return void
*/
public function __construct()
{
$this->middleware($this->guestMiddleware(), ['except' => 'logout']);
}
/**
* Get a validator for an incoming registration request.
*
* #param array $data
* #return \Illuminate\Contracts\Validation\Validator
*/
protected function validator(array $data)
{
return Validator::make($data, [
'name' => 'required|max:255',
'email' => 'required|email|max:255|unique:users',
'practice' => 'required',
'password' => 'required|min:6|confirmed',
]);
}
/**
* Create a new user instance after a valid registration.
*
* #param array $data
* #return User
*/
protected function create(array $data)
{
//Validation
$this->validate($data, [
'name' => 'required|max:255',
'email' => 'required|email|max:255|unique:users',
'practice' => 'required|max:255',
'phone_number' => 'required|number',
'password' => 'required|min:6|confirmed',
]);
$insertedUserInfo = User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
]);
// echo '<pre>'.print_r($userinfo,1).'</pre>';
// exit;
// $userinfo = new Userinfo;
// $userinfo->user_id = $insertedUserInfo->id;
// $userinfo->phone_number = $data['phone_number'];
// $userinfo->address = $data['address'];
// return $userinfo->save();
Userinfo::create([
'user_id' => $insertedUserInfo->id,
'phone_number' => $data['phone_number'],
'practice' => $data['practice'],
'dob' => $data['dob'],
'postcode' => $data['postcode'],
'gender' => $data['gender']
]);
return $insertedUserInfo;
}
}
Please help me to validate registration from this from data goes to 3tables users,userinfo tables.
First of all for this type of steps layout you should have some client side validation too.
For that you can use jquery validate.
Take a look at this
your validator will only validate fields inside array
$this->validate($data, [
'name' => 'required|max:255',
'email' => 'required|email|max:255|unique:users',
'practice' => 'required|max:255',
'phone_number' => 'required|number',
'password' => 'required|min:6|confirmed',
]);
So you have to pass field names to your validation array to validate that field.
Validate method expect 1st param as Request instance, but not array($data) as you made.
https://laravel.com/api/5.1/Illuminate/Foundation/Validation/ValidatesRequests.html#method_validate