How to add grammarly plugin in laravel forms? - php

I have this file
#section('content')
<form method="post" action="{{ route('member.articles.store') }}" enctype="multipart/form-data"
onSubmit="submit.disabled=true; submit.value='{{ __('Submitting ...') }}'; return true;">
#csrf
<div class="card bg-light">
<div class="card-header">{{ __('Add Article') }}</div>
<div class="card-body">
<div class="form-group">
{{ Form::label('title', __('Title')) }}
{{ Form::text('title', old('title'), ['class' => 'form-control', 'required' => true, 'maxlength' => 190]) }}
</div>
<div class="form-group" style="display: none">
{{ Form::label('slug', __('Slug(URL Key)')) }}
{{ Form::text('slug', old('slug'), ['class' => 'form-control', 'maxlength' => 190]) }}
</div>
<div class="form-group">
{{ Form::label('category', __('Category')) }}
{{ Form::select('category', $categories, old('category'),
['class' => 'form-control select2', 'required' => true]) }}
</div>
<div class="form-group">
{{ Form::label('content', __('Content')) }}
{{ Form::textarea('content', old('content'), ['class' => 'form-control text-editor'])}}
</div>
And i want to add grammarly plugin in content area.
FYI: https://developer.grammarly.com/docs/api/editor-sdk/
I tried this but not working:-
<div class="form-group">
{{ Form::label('content', __('Content')) }}
<grammarly-editor-plugin>
{{ Form::textarea('content', old('content'), ['class' => 'form-control text-editor'])}}
</grammarly-editor-plugin>
</div>

Related

File Not Updating in Laravel

I have Laravel 5.5 Application. I am trying to update my post and image is not updating. When I die and dump the following
dd($request->hasFile('image'));
it outputs false
View:
<div class="box-body">
{{ Form::model($slider, array('route' => array('admin.slider.update', $slider->title), 'method' => 'PUT')) }}
<div class="form-group">
{!! Form::label('title', 'Title') !!}
{!! Form::text('title', null, ['class' => 'form-control', 'placeholder' => 'Title']) !!}
</div>
<div class="form-group">
{!! Form::label('content', 'Content') !!}
{!! Form::textarea('content', null, ['class' => 'form-control', 'placeholder' => 'Content']) !!}
</div>
<div class="row">
<div class="col-md-2 col-xs-6">
<div class="form-group">
{!! Form::label('image', 'Change Image') !!}
{!! Form::file('image') !!}
</div>
</div>
<div class="col-md-10 col-xs-6">
<img src="{{ secure_asset('images/slider/thumb/' . $slider->image )}}" class="img-responsive" width="150">
{{ $slider->image }}
</div>
</div>
{!! Form::submit('Submit', array( 'class'=>'btn btn-info' )) !!}
{!! Form::close() !!}
</div>
Controller:
public function sliderupdate($slider, Request $request){
$slider = Slider::where('title', $slider)->firstorfail();
$slider->title = $request->title;
$slider->content = $request->content;
dd($request->hasFile('image'));
if ($request->hasFile('image')) {
$file = Input::file('image');
//getting timestamp
$timestamp = str_replace([' ', ':'], '-', Carbon::now()->toDateTimeString());
$name = $timestamp. '-' .$file->getClientOriginalName();
$file->move(public_path().'/images/slider/', $name);
$slider->image = $name;
$thumb = Image::make(public_path().'/images/slider/' . $name)->resize(1920,1080)->save(public_path().'/images/slider/thumb/' . $name, 90);
}
$slider->save();
return redirect()->route('admin.slider.edit', $slider->title)->with('status', 'Update Success');
}
Route:
Route::put('admin/slider/{slider}', [
'uses' => 'AdminController#sliderupdate',
'as' => 'admin.slider.update'
]);
Something I am missing, but couldn't find out what it is.
You are missing the 'files' => true option. You need files option in the array passed to Form::open or Form::model if you are going to accept files.
{{ Form::model($slider, [
'route' => ['admin.slider.update', $slider->title],
'method' => 'PUT',
'files' => true
]) }}
Method:
public function slideredit($slider){
$slider = Slider::where('title', $slider)->firstOrFail();
return view('admin.slider.edit', compact('slider'));
}
Change your Form to
{!! Form::model($slider, ['route' => ['admin.slider.post', $slider->title, 'method' => 'PUT', 'files'=>true]]) !!}
<div class="modal-body">
<!-- text input -->
<div class="form-group">
{!! Form::label('title', 'Title') !!}
{!! Form::text('title', null, ['class' => 'form-control', 'placeholder' => 'Title']) !!}
</div>
<div class="form-group">
{!! Form::label('content', 'Content') !!}
{!! Form::textarea('content', null, ['class' => 'form-control', 'placeholder' => 'Content']) !!}
</div>
<div class="form-group">
{!! Form::label('image', 'Choose Image') !!}
{!! Form::file('image') !!}
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default pull-left" data-dismiss="modal">Close</button>
{!! Form::submit('Submit', array( 'class'=>'btn btn-info')) !!}
</div>
{!! Form::close() !!}

Laravel 5.3 - Sometimes views get broken and show script

I think it's a bit hard to explain with words so I put some screenshots. Sometimes the view get broken after several refresh like 2 out of 5 tries. It always break on content right div until the end of the page.
Not Break: https://i.stack.imgur.com/vpRJU.png
Break After Several Refresh: https://i.stack.imgur.com/swbQ1.png
I think the problem can be at my master blade layout or the page.
This is the Master Blade Layout
<!DOCTYPE html> <html lang="en">
<head>
#include('partial._head')
</head>
<body>
<div class="container main-container">
<div class="row row-bg">
#include('partial._nav')
</div>
<div class="row row-bg">
#include('partial._title')
</div>
<div class="row row-bg">
<div class="col-md-10 col-md-offset-1 content-container">
<div class="text-center text-uppercase content-title">
#yield('content-title')
#yield('session')
</div>
<hr>
<div class="content">
#yield('content')
</div>
</div>
</div>
<div class="row row-bg pb-1">
<div class="col-md-5 col-md-offset-1 content-left">
#yield('content-left')
</div>
<div class="col-md-5 content-right">
#yield('content-right')
</div>
</div>
</div>
#include('partial._footer')
#include('partial._script')
</body>
</html>
This is the Page code
#extends('main')
#section('title', 'Registrasi Akun')
#section('content-title')
Registrasi Akun
#stop
#section('content')
<div class="col-sm-12">
{!! Form::open(['method' => 'POST', 'route' => 'register', 'class' => 'form-horizontal' ]) !!}
<div class="form-group{{ $errors->has('username') ? ' has-error' : '' }}">
{!! Form::label('username', 'Username', ['class' => 'col-sm-3 control-label']) !!}
<div class="col-sm-9">
{!! Form::text('username', null, ['class' => 'form-control',
'required' => 'required',
'minlength' => '6',
'maxlength' => '15',
'pattern' => '^[a-zA-Z0-9_-]*$',
'title' => 'only accept alphanum and dashes'
]) !!}
<small class="text-danger">{{ $errors->first('username') }}</small>
</div>
</div>
<div class="form-group{{ $errors->has('password') ? ' has-error' : '' }}">
{!! Form::label('password', 'Password', ['class' => 'col-sm-3 control-label']) !!}
<div class="col-sm-9">
{!! Form::password('password', ['class' => 'form-control',
'required' => 'required',
'minlength' => '8',
'maxlength' => '16'
]) !!}
<small class="text-danger">{{ $errors->first('password') }}</small>
</div>
</div>
<div class="form-group{{ $errors->has('password_confirmation') ? ' has-error' : '' }}">
{!! Form::label('password_confirmation', 'Password Again', ['class' => 'col-sm-3 control-label']) !!}
<div class="col-sm-9">
{!! Form::password('password_confirmation', ['class' => 'form-control',
'required' => 'required'
]) !!}
<small class="text-danger">{{ $errors->first('password_confirmation') }}</small>
</div>
</div>
<hr>
<div class="form-group{{ $errors->has('fullname') ? ' has-error' : '' }}">
{!! Form::label('fullname', 'Nama Lengkap', ['class' => 'col-sm-3 control-label']) !!}
<div class="col-sm-9">
{!! Form::text('fullname', null, ['class' => 'form-control',
'required' => 'required',
'pattern' => '^[a-zA-Z ]*$',
'title' => 'only accept alphabet and spaces'
]) !!}
<small class="text-danger">{{ $errors->first('fullname') }}</small>
</div>
</div>
<div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}">
{!! Form::label('email', 'Email', ['class' =>'col-sm-3 control-label']) !!}
<div class="col-sm-9">
{!! Form::email('email', null, ['class' => 'form-control',
'required' => 'required',
'placeholder' => 'eg: foo#bar.com'
]) !!}
<small class="text-danger">{{ $errors->first('email') }}</small>
</div>
</div>
<div class="form-group{{ $errors->has('phone_number') ? ' has-error' : '' }}">
{!! Form::label('phone_number', 'No. Telepon', ['class' => 'col-sm-3 control-label']) !!}
<div class="col-sm-9">
{!! Form::text('phone_number', null, ['class' => 'form-control',
'required' => 'required',
'pattern' => '^[0-9]*$',
'title' => 'input number only eg: 081222333444'
]) !!}
<small class="text-danger">{{ $errors->first('phone_number') }}</small>
</div>
</div>
<div class="form-group{{ $errors->has('gender') ? ' has-error' : '' }}">
{!! Form::label('gender', 'Input label', ['class' => 'col-sm-3 control-label']) !!}
<div class="col-sm-9">
{!! Form::select('gender', [null => 'Choose...', 'male' => 'Pria', 'female' => 'Wanita'], null, ['id' => 'gender', 'class' => 'form-control',
'required' => 'required'
]) !!}
<small class="text-danger">{{ $errors->first('gender') }}</small>
</div>
</div>
<div class="form-group{{ $errors->has('address') ? ' has-error' : '' }}">
{!! Form::label('address', 'Input', ['class' => 'col-sm-3 control-label']) !!}
<div class="col-sm-9">
{!! Form::textarea('address', null, ['class' => 'form-control',
'required' => 'required',
'minlength' => '50'
]) !!}
<small class="text-danger">{{ $errors->first('address') }}</small>
</div>
</div>
</div>
#stop
#section('content-left')
<div class="form-group">
<div class="checkbox{{ $errors->has('setuju') ? ' has-error' : '' }}">
<label for="setuju" class="text-white">
{!! Form::checkbox('setuju', '1', 0, ['id' => 'setuju', 'required' => 'required']) !!}
Saya telah membaca dan menerima <br> <a class="disini" data-toggle="modal" data-target="#syarat" href="#">Syarat dan Peraturan</a> dari Garena.
</label>
</div>
<small class="text-danger">{{ $errors->first('setuju') }}</small>
</div>
#include('partial._modal')
#stop
#section('content-right')
{!! Form::submit('Register', ['class' => 'btn this-btn btn-garena pull-right']) !!}
{!! Form::close() !!}
#stop
#section('scripts')
<script>
var password = document.getElementById("password"),
confirm_password = document.getElementById("password_confirmation");
function validatePassword(){
if(password.value != confirm_password.value) {
confirm_password.setCustomValidity("Passwords Don't Match");
} else {
confirm_password.setCustomValidity('');
}
}
password.onchange = validatePassword;
confirm_password.onkeyup = validatePassword;
</script>
#stop
where is your 'scripts' yield ?
according to this line #section('scripts') you should have one.

htmlentities() expects parameter 1 to be string, array given when submitting the for

I have this form elements that contains text, select and text which generates array of the received data. for eg: {{ Form::text('email[]', null, ['class' => 'form-control', 'placeholder' => trans('Email')]) }}
If I do not validate the data displays just fine. but when I submit with validation error is displayed.
<div id="home" class="tab-pane fade in active">
<h3>Company Detail
</h3>
<div class="form-group">
{{ Form::label('name', 'Name', ['class' => 'col-lg-2 control-label']) }}
<div class="col-lg-10">
{{ Form::text('name', null, ['class' => 'form-control', 'placeholder' => trans('Name')]) }}
</div>
<!--col-lg-10-->
</div>
<div class="form-group">
{{ Form::label('country_id', 'Country', ['class' => 'col-lg-2 control-label']) }}
<div class="col-lg-10">
{{ Form::select('country_id', $country, null, ['class' => 'form-control']) }}
</div>
<!--col-lg-10-->
</div>
<!--form control-->
<div class="form-group">
{{ Form::label('city_id', 'City', ['class' => 'col-lg-2 control-label']) }}
<div class="col-lg-10">
{{ Form::select('city_id', $city, null, ['class' => 'form-control']) }}
</div>
<!--col-lg-10-->
</div>
<!--form control-->
<div class="form-group">
{{ Form::label('companyType_id', 'Company Type', ['class' => 'col-lg-2 control-label']) }}
<div class="col-lg-10">
{{ Form::select('companyType_id', $companyType, null, ['class' => 'form-control']) }}
</div>
<!--col-lg-10-->
</div>
<!--form control-->
<div class="form-group">
{{ Form::label('companySubType_id', 'Company Sub Type', ['class' => 'col-lg-2 control-label']) }}
<div class="col-lg-10">
{{ Form::select('companySubType_id', $companySubType, null, ['class' => 'form-control']) }}
</div>
<!--col-lg-10-->
</div>
<!--form control-->
<div class="form-group">
{{ Form::label('description', 'Description', ['class' => 'col-lg-2 control-label']) }}
<div class="col-lg-10">
{{ Form::text('description', null, ['class' => 'form-control', 'placeholder' => trans('Discription')]) }}
</div>
<!--col-lg-10-->
</div>
<!--form control-->
<div class="form-group">
{{ Form::label('established_year', 'Established Year', ['class' => 'col-lg-2 control-label']) }}
<div class="col-lg-10">
{{ Form::selectYear('year', 1950, date('Y'), null, ['class' => 'form-control']) }}
</div>
<!--col-lg-10-->
</div>
<!--form control-->
<div class="form-group">
{{ Form::label('location', 'Address', ['class' => 'col-lg-2 control-label']) }}
<div class="col-lg-10">
{{ Form::text('location', null, ['class' => 'form-control', 'placeholder' => trans('Address')]) }}
</div>
<!--col-lg-10-->
</div>
<!--form control-->
<div class="form-group">
{{ Form::label('number_of_employees', 'Number Of Employees', ['class' => 'col-lg-2 control-label']) }}
<div class="col-lg-10">
{{ Form::text('number_of_employees', null, ['class' => 'form-control', 'placeholder' => trans('Number Of Employees')]) }}
</div>
<!--col-lg-10-->
</div>
<!--form control-->
</div>
<div id="menu1" class="tab-pane fade">
<h3>Other Detail
</h3>
<div class="form-group">
{{ Form::label('email', 'Email', ['class' => 'col-lg-2 control-label']) }}
<div class="col-lg-10">
<div id="addEmailField">
<p>{{ Form::text('email[]', null, ['class' => 'form-control', 'placeholder' => trans('Email')]) }}
</p>
</div>
<p>
<input type="button" value="Add Email Field" onclick="addEmail();" class="btn btn-success" />
</p>
</div>
<!--col-lg-10-->
</div>
<div class="form-group">
{{ Form::label('phone_type', 'Phone', ['class' => 'col-lg-2 control-label']) }}
<div class="col-lg-10">
<div class="form-inline" id="addPhoneField">
<p>
{{ Form::select('phone_type[]', ['home'=>'Home', 'work'=>'Work', 'mobile'=>'Mobile', 'fax'=>'Fax'], null, ['class' => 'form-control']) }}
{{ Form::text('phone_number[]', null, ['class' => 'form-control', 'placeholder' => trans('Phone Number')]) }}
</p>
</div>
<p>
<input type="button" value="Add Phone Field" onclick="addPhone();" class="btn btn-success" />
</p>
</div>
<!--col-lg-10-->
</div>
<div class="form-group">
{{ Form::label('website_url', 'Website Url', ['class' => 'col-lg-2 control-label']) }}
<div class="col-lg-10">
<div id="addWebsiteField">
<p>
{{ Form::text('website_url[]', null, ['class' => 'form-control', 'placeholder' => trans('Website Url')]) }}
</p>
</div>
<p>
<input type="button" value="Add Website Field" onclick="addWebsite();" class="btn btn-success" />
</p>
</div>
<!--col-lg-10-->
</div>
</div>
<div id="menu2" class="tab-pane fade">
<h3>Menu 2
</h3>
<div class="form-group">
{{ Form::label('Sunday_open', 'Sunday Open', ['class' => 'col-lg-2 control-label']) }}
<div class="col-lg-10">
{{ Form::text('Sunday_open', null, ['class' => 'form-control', 'placeholder' => trans('Sunday Open')]) }}
</div>
<!--col-lg-10-->
</div>
<div class="form-group">
{{ Form::label('Sunday_close', 'Sunday Close', ['class' => 'col-lg-2 control-label']) }}
<div class="col-lg-10">
{{ Form::text('Sunday_close', null, ['class' => 'form-control', 'placeholder' => trans('Sunday Close')]) }}
</div>
<!--col-lg-10-->
</div>
<div class="form-group">
{{ Form::label('Monday_open', 'Monday Open', ['class' => 'col-lg-2 control-label']) }}
<div class="col-lg-10">
{{ Form::text('Monday_open', null, ['class' => 'form-control', 'placeholder' => trans('Monday Open')]) }}
</div>
<!--col-lg-10-->
</div>
<div class="form-group">
{{ Form::label('Monday_close', 'Monday Close', ['class' => 'col-lg-2 control-label']) }}
<div class="col-lg-10">
{{ Form::text('Monday_close', null, ['class' => 'form-control', 'placeholder' => trans('Monday Close')]) }}
</div>
<!--col-lg-10-->
</div>
<div class="form-group">
{{ Form::label('Tuesday_open', 'Tuesday Open', ['class' => 'col-lg-2 control-label']) }}
<div class="col-lg-10">
{{ Form::text('Tuesday_open', null, ['class' => 'form-control', 'placeholder' => trans('Tuesday Open')]) }}
</div>
<!--col-lg-10-->
</div>
<div class="form-group">
{{ Form::label('Tuesday_close', 'Tuesday Close', ['class' => 'col-lg-2 control-label']) }}
<div class="col-lg-10">
{{ Form::text('Tuesday_close', null, ['class' => 'form-control', 'placeholder' => trans('Tuesday Close')]) }}
</div>
<!--col-lg-10-->
</div>
<div class="form-group">
{{ Form::label('Wednesday_open', 'Wednesday Open', ['class' => 'col-lg-2 control-label']) }}
<div class="col-lg-10">
{{ Form::text('Wednesday_open', null, ['class' => 'form-control', 'placeholder' => trans('Wednesday Open')]) }}
</div>
<!--col-lg-10-->
</div>
<div class="form-group">
{{ Form::label('Wednesday_close', 'Wednesday Close', ['class' => 'col-lg-2 control-label']) }}
<div class="col-lg-10">
{{ Form::text('Wednesday_close', null, ['class' => 'form-control', 'placeholder' => trans('Wednesday Close')]) }}
</div>
<!--col-lg-10-->
</div>
<div class="form-group">
{{ Form::label('Thursday_open', 'Thursday Open', ['class' => 'col-lg-2 control-label']) }}
<div class="col-lg-10">
{{ Form::text('Thursday_open', null, ['class' => 'form-control', 'placeholder' => trans('Thursday Open')]) }}
</div>
<!--col-lg-10-->
</div>
<div class="form-group">
{{ Form::label('Thursday_close', 'Thursday Close', ['class' => 'col-lg-2 control-label']) }}
<div class="col-lg-10">
{{ Form::text('Thursday_close', null, ['class' => 'form-control', 'placeholder' => trans('Thursday Close')]) }}
</div>
<!--col-lg-10-->
</div>
<div class="form-group">
{{ Form::label('Friday_open', 'Friday Open', ['class' => 'col-lg-2 control-label']) }}
<div class="col-lg-10">
{{ Form::text('Friday_open', null, ['class' => 'form-control', 'placeholder' => trans('Friday Open')]) }}
</div>
<!--col-lg-10-->
</div>
<div class="form-group">
{{ Form::label('Friday_close', 'Friday Close', ['class' => 'col-lg-2 control-label']) }}
<div class="col-lg-10">
{{ Form::text('Friday_close', null, ['class' => 'form-control', 'placeholder' => trans('Friday Close')]) }}
</div>
<!--col-lg-10-->
</div>
<div class="form-group">
{{ Form::label('Saturday_open', 'Saturday Open', ['class' => 'col-lg-2 control-label']) }}
<div class="col-lg-10">
{{ Form::text('Saturday_open', null, ['class' => 'form-control', 'placeholder' => trans('Saturday Open')]) }}
</div>
<!--col-lg-10-->
</div>
<div class="form-group">
{{ Form::label('Saturday_close', 'Saturday Close', ['class' => 'col-lg-2 control-label']) }}
<div class="col-lg-10">
{{ Form::text('Saturday_close', null, ['class' => 'form-control', 'placeholder' => trans('Saturday Close')]) }}
</div>
<!--col-lg-10-->
</div>
</div>
<div id="menu3" class="tab-pane fade">
<h3>Branch
</h3>
<div id="addBranchField">
<div class="form-group">
{{ Form::label('location', 'Location', ['class' => 'col-lg-2 control-label']) }}
<div class="col-lg-10">
{{ Form::text('location[]', null, ['class' => 'form-control', 'placeholder' => trans('Location')]) }}
</div>
<!--col-lg-10-->
</div>
<div class="form-group">
{{ Form::label('branch_description', 'Description', ['class' => 'col-lg-2 control-label']) }}
<div class="col-lg-10">
{{ Form::text('branch_description[]', null, ['class' => 'form-control', 'placeholder' => trans('Description')]) }}
</div>
<!--col-lg-10-->
</div>
<div class="form-group">
{{ Form::label('long', 'Longitude', ['class' => 'col-lg-2 control-label']) }}
<div class="col-lg-10">
{{ Form::text('long[]', null, ['class' => 'form-control', 'placeholder' => trans('Longitude')]) }}
</div>
<!--col-lg-10-->
</div>
<div class="form-group">
{{ Form::label('lat', 'Latitude', ['class' => 'col-lg-2 control-label']) }}
<div class="col-lg-10">
{{ Form::text('lat[]', null, ['class' => 'form-control', 'placeholder' => trans('Latitude')]) }}
</div>
<!--col-lg-10-->
</div>
</div>
<!-- addBranchField -->
<p class="col-lg-offset-2">
<input type="button" value="Add Branch Field" onclick="addBranchField();" class="btn btn-success" />
</p>
</div>
as you can see there are input that takes array of values. When I submit the form it displays error.
Also I have the rules for the form
$this->validate($request, [
'companyName' => 'required',
]);
for now I am just printing the submitted value. print_r($request->all());
$this->validate($request, [
'email.*' => 'required',
]);
try to validate array type input data this way

Call to a member function getClientOriginalName() on a non-object in Laravel 4

I have this problem in my Public function Store of Laravel 4, i can upload an update images, pretty cool, but I cannot create a new record :( appears: Call to a member function getClientOriginalName() on a non-object, in this line:
$filename = $image->getClientOriginalName();This is complete code.
public function store(){
$image = Input::file('image');` <br/>
$filename = $image->getClientOriginalName();
if(Input::hasFile('image')){
Input::file('image')->move(public_path().'/assets/img/', $filename);
}
$titulo = new Titulo();
$titulo->id = Input::get('id');
$titulo->title = Input::get('title');
$titulo->description = Input::get('description');
$titulo->date = Input::get('date');
$titulo->image = $filename;
$titulo->category_id = Input::get('category_id');
$titulo->save();
}
This is my form
{{ Form::open (['route' => 'titulos.store', 'class'=> 'form', 'method' =>'post', 'files'=> 'true']) }}
{{ Form::label('title', "Titulo:", ['class' => 'col-sm-2 control-label']) }}
{{ Form::text('title') }}
{{ $errors->first('title') }}
<div class="form-group">
{{ Form::label('date', "Fecha:", ['class' => 'col-sm-2 control-label']) }}
<input type="date" name="date" >
</div>
{{ Form::label('description', "Description:", ['class' => 'col-sm-2 control-label']) }}
{{ Form::textarea('description') }}
{{ $errors->first('description') }}
<div class="form-group">
{{ Form::file('image') }}
</div>
{{ Form::label('category_id', 'Category:', ['class' => 'col-sm-2 control-label']) }}
<div class="col-sm-10">
{{ Form::select('category_id', array('1' => 'TBLeaks', '2' => 'Quejas', '3' => 'Denuncias', '4' => 'Ideas'), null, array('class' => 'form-control')) }}
</div>
<div class="row">
<div class="col-sm-offset-2 col-sm-10">
{{ Form::submit('Submit', ['class' => "btn btn-primary"]) }}
</div>
</div>
<div class="row">
<div class="col-sm-offset-2 col-sm-10">
<a class="btn btn-success" href="{{ URL::to('admin') }}">Back to Admin</a>
</div>
</div>
{{ Form::close() }}
</div>
You missed the enctype part. Your open form should be
{{ Form::open (['route' => 'titulos.store', 'enctype' => 'multipart/form-data', 'class'=> 'form', 'method' =>'post', 'files'=> 'true']) }}

laravel 5 - about validation, i'm confused

To much apporoaches, my controller:
public function store(Request $request)
{
$this->validate($request, ['title' => 'required',
'date' => 'required',
'image_1' => 'required|mimes:png,jpeg',
]);
$user = Auth::user()->id;
$report = new Report($request->all());
$report->author_id = $user;
$image = $request->file('image_1');
$destinationPath = 'uploads/reports';
$ext = $image->getClientOriginalExtension();
$fileName = rand(11111,99999).'.'.$ext;
$report->image_1 = $image->move($destinationPath, $fileName);
$report->save();
Session::flash('flash_message', 'Report added!');
return redirect('dash/reports');
}
and my create view is:
#extends('layouts.app')
#section('content')
<div class="container">
<h1>Crea un report</h1>
<p>I campi sono tutti obbligatori. In caso di difficoltà, fare riferimento ad <strong>eloquent</strong> l'assistente virtuale.</p>
<hr/>
{!! Form::open(['url' => '/dash/reports', 'files' => true, 'class' => 'form-horizontal']) !!}
<div class="form-group {{ $errors->has('title') ? 'has-error' : ''}}">
{!! Form::label('fake', 'Nome e cognome', ['class' => 'col-sm-3 control-label']) !!}
<div class="col-sm-6">
<input class="form-control" id="disabledInput" type="text" placeholder="{{ $author->name }} {{ $author->surname}}" disabled>
</div>
</div>
<div class="form-group {{ $errors->has('title') ? 'has-error' : ''}}">
{!! Form::label('title', 'Servizio', ['class' => 'col-sm-3 control-label']) !!}
<div class="col-sm-6">
{!! Form::text('title', null, ['class' => 'form-control', 'required' => 'required']) !!}
{!! $errors->first('title', '<p class="help-block">:message</p>') !!}
</div>
</div>
<div class="form-group {{ $errors->has('title') ? 'has-error' : ''}}">
{!! Form::label('date', 'Data', ['class' => 'col-sm-3 control-label']) !!}
<div class="col-sm-6">
{!! Form::text('date', \Carbon\Carbon::now()->format('d/m/Y'), ['class' => 'form-control', 'required' => 'required']) !!}
{!! $errors->first('date', '<p class="help-block">:message</p>') !!}
</div>
</div>
<div class="form-group {{ $errors->has('category_id') ? 'has-error' : ''}}">
{!! Form::label('category_id', 'Cliente', ['class' => 'col-sm-3 control-label']) !!}
<div class="col-sm-6">
{!! Form::select('category_id', $category, null, ['class' => 'form-control'] ) !!}
{!! $errors->first('category_id', '<p class="help-block">:message</p>') !!}
</div>
</div>
<div class="form-group {{ $errors->has('image_1') ? 'has-error' : ''}}">
{!! Form::label('image_1', 'Upload report cartaceo', ['class' => 'col-sm-3 control-label']) !!}
<div class="col-sm-6">
<p>Solo immagini .jpg/.png</p>
{!! Form::file('image_1', null, ['class' => 'form-control', 'required' => 'required']) !!}
{!! $errors->first('image_1', '<p class="help-block">:message</p>') !!}
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-3 col-sm-3">
{!! Form::submit('Create', ['class' => 'btn btn-primary form-control']) !!}
</div>
</div>
{!! Form::close() !!}
#if ($errors->any())
<ul class="alert alert-danger">
#foreach ($errors->all() as $error)
<li>{{ $error }}</li>
#endforeach
</ul>
#endif
</div>
#endsection
Now, if I submit a form with a error, nothing appear, why? Also, my "session flash" does not work, i just use the apzzcoder/crud generator, i just follow the guide. Validation work correctly, but nothing appear

Categories