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
Related
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>
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() !!}
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.
I have a test set up like this
use WithoutMiddleware;
public function test_it_submits_forms()
{
$this->visit('/admin/menu/samples')
->click('New Sample')
->seePageIs('/admin/menu/samples/new/create')
->type('test1', 'name')
->type('test2','description')
->type('test2','introduction')
->select(11, 'scenario_id')
->type('test','slug')
->press('Add');
}
and the file I am testing like this.
{!! Form::open(['url' => 'admin/menu/samples/', 'method' => 'POST']) !!}
<div class="row"><div class="form-group col-xs-8 col-md-7 {!! $errors->has('name') ? 'has-
error' : '' !!}">
{!! Form::label('name', 'Name:') !!}
{!! Form::text('name', null,['class' => 'form-control']) !!}
{!! $errors->first('name', '<span class="help-block">:message</span>')!!}
</div>
<div class="form-group col-xs-8 col-md-7">
{!! Form::label('introduction', 'Introduction:') !!}
{!! Form::textarea('introduction',null, ['class' => 'form-control']) !!}
</div>
<div class="form-group col-xs-8 col-md-7">
{!! Form::label('description', 'Description:') !!}
{!! Form::textarea('description',null, ['class' => 'form-control']) !!}
</div>
<div class="form-group col-xs-8 col-md-7 {!! $errors->has('slug') ? 'has-error' : '' !!}">
{!! Form::label('slug', 'URL:') !!}
{!! Form::text('slug',null, ['class' => 'form-control']) !!}
{!! $errors->first('slug', '<span class="help-block">:message</span>') !!}
</div>
<div class="form-group col-xs-8 col-md-7">
{!! Form::label('available_from', 'Available from:') !!}
{!! Form::date('available_from', \Carbon\Carbon::now(), ['class' => 'form-control2']) !!}
</div>
<div class="form-group col-xs-8 col-md-7">
{!! Form::label('available_until', 'Available until:') !!}
{!! Form::date('available_until', \Carbon\Carbon::now(), ['class' => 'form-control2']) !!}
</div>
<div class="form-group col-xs-8 col-md-7">
{!! Form::label('needs_auth', 'Needs authentication:') !!}
{!! Form::checkbox('needs_auth', 'value', false) !!}
</div>
<div class="form-group col-xs-8 col-md-7">
{!! Form::label('is_active', 'Active:') !!}
{!! Form::checkbox('is_active', 'value', false) !!}
</div>
<div class="form-group col-xs-8 col-md-7">
<h3>Add a scenario</h3>
{!! Form::select('scenario_id',($scenario), null,
['id'=>'scenario_id','placeholder' => 'Select one...']) !!}
</div>
<div class="form-group col-xs-8 col-md-7">
{!! Form::submit('Add', ['class' => 'btn btn-primary']) !!}
</div>
{!! Form::close() !!}
The test throws undefined variable errors on both of the variables $errors in form elements name and slug ( they just light up the form if something is not filled properly).
Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(8, 'Undefined varia...', '/home/vagrant/C...', 9, Array)
Could anyone tell why and how to fix this? The $errors variable should always be there by Laravel standards...
The $errors variable should always be there by Laravel standards...
Unless you disable the middleware!
The feature is implemented by having the ShareErrorsFromSession being enabled; which you just disabled.
The answer at Temporarily disable / bypass Middleware has some pointers form here on.
I have a problem using #yield from one view to another. I couldn't get anything from my question.blade.php file, even if using just a simple text.
My create.blade.php file:
#extends('layout/layoutAdmin')
#section('content')
<div class="container">
<h1>Add a new inventory</h1>
{!! Form::open(['url' => 'admin/menu/inventories/', 'method' => 'POST']) !!}
<div class="row">
<div class="form-group col-xs-8 col-md-7 {!! $errors->has('text') ? 'has-error' : '' !!}">
{!! Form::label('text', 'Name:') !!}
{!! Form::text('text', null,['class' => 'form-control']) !!}
{!! $errors->first('text', '<span class="help-block">:message</span>') !!}
</div>
<div class="form-group col-xs-8 col-md-7">
{!! Form::label('description', 'Description:') !!}
{!! Form::textarea('description', null, ['class' => 'form-control']) !!}
</div>
#yield('content2')
</div>
</div>
{!! Form::close() !!}
#stop
And my question.blade.php file:
#extends('inventory.create')
#section('content2')
<div class="form-group col-xs-8 col-md-7">
{!! Form::label('type', 'Type:') !!}
{!! Form::number('type', null, ['class' => 'form-control']) !!}
</div>
<div class="form-group col-xs-8 col-md-7 {!! $errors->has('introduction') ? 'has-error' : '' !!}">
{!! Form::label('introduction', 'Introductory Text:') !!}
{!! Form::textarea('introduction', null, ['class' => 'form-control']) !!}
{!! $errors->first('introduction', '<span class="help-block">:message</span>') !!}
</div>
<div class="form-group col-xs-8 col-md-7">
{!! Form::label('value', 'Values:') !!}
{!! Form::textarea('value', null, ['class' => 'form-control']) !!}
</div>
<div class="form-group col-xs-8 col-md-7 {!! $errors->has('language') ? 'has-error' : '' !!}">
{!! Form::label('language', 'Language:') !!}
{!! Form::text('language', null, ['class' => 'form-control']) !!}
{!! $errors->first('language', '<span class="help-block">:message</span>') !!}
</div>
<div class="form-group col-xs-8 col-md-7">
{!! Form::label('is_active', 'Active:') !!}
{!! Form::checkbox('is_active', null, ['class' => 'form-control']) !!}
</div>
#stop
My QuestionController:
public function create()
{
return view('inventory.question');
}
Route:
Route::get('admin/menu/inventories/new/question', 'QuestionController#create');
Edit: fixed the typo
You are yielding to a section called container2 and you have placed your content in a section called content2.