I have 2 select box in this form, the first select box is done and works.
...But when I add the second select box, the error appears like the picture..
here's the code
This is the first select box - it works:
{{ Form::open(array('url' =>route('units.store'), 'method' => 'post' ))}}
<div class="form-group #if ($errors->has('brand_id')) has-error #endif">
<label>Brand Manufacture</label>
{{Form::select('brand_id', $brand, null, ['class' => 'form-control w450']) }}
#if ($errors->has('brand_id')) <p class="help-block">{{ $errors->first('brand_id') }}</p> #endif
</div>
And this is the select that is not right:
<div class="form-group #if ($errors->has('model_id')) has-error #endif">
<label>Model Type</label>
{{Form::select('model_id',$model, null, ['class' => 'form-control w450']) }}
#if ($errors->has('model_id')) <p class="help-block">{{ $errors->first('model_id') }}</p> #endif
</div>
And this is the whole code.
{{ Form::open(array('url' =>route('units.store'), 'method' => 'post' ))}}
<div class="form-group #if ($errors->has('brand_id')) has-error #endif">
<label>Brand Manufacture</label>
{{Form::select('brand_id', $brand, null, ['class' => 'form-control w450']) }}
#if ($errors->has('brand_id')) <p class="help-block">{{ $errors->first('brand_id') }}</p> #endif
</div>
<div class="form-group #if ($errors->has('model_id')) has-error #endif">
<label>Model Type</label>
{{Form::select('model_id',$model, null, ['class' => 'form-control w450']) }}
#if ($errors->has('model_id')) <p class="help-block">{{ $errors->first('model_id') }}</p> #endif
</div>
<div class="form-group #if ($errors->has('kva')) has-error #endif">
<label>kva</label>
<input name="kva" type="text" class="form-control w450" value="{{ Input::old('kva') }}">
#if ($errors->has('kva')) <p class="help-block">{{ $errors->first('kva') }}</p> #endif
</div>
<div class="form-group #if ($errors->has('type')) has-error #endif">
<label>Type</label>
<select name="type" id="" class="form-control w450">
<option value="OPEN">OPEN</option>
<option value="CLOSE">CLOSE</option>
</select>
#if ($errors->has('type')) <p class="help-block">{{ $errors->first('type') }}</p> #endif
</div>
<div class="form-group #if ($errors->has('sn')) has-error #endif">
<label>Serial Number</label>
<input name="sn" type="text" class="form-control w450" value="{{ Input::old('sn') }}">
#if ($errors->has('sn')) <p class="help-block">{{ $errors->first('sn') }}</p> #endif
</div>
<div class="form-group #if ($errors->has('wbs_unit')) has-error #endif">
<label>WBS unit</label>
<input name="wbs_unit" type="text" class="form-control w450" value="{{ Input::old('wbs_unit') }}">
#if ($errors->has('wbs_unit')) <p class="help-block">{{ $errors->first('wbs_unit') }}</p> #endif
</div>
<div class="form-group">
<button type="submit" class="btn btn-sm btn-primary">create</button>
</div>
{{ Form::close() }}
I can't post any image :(
so help me..please
Make sure you're pulling data from the database in the correct format for the select box. It should be an associative array with the key being the database ID and the value being the string you want to show in the dropdown. Here's an example.
$brands = Brand::lists('name', 'id');
// Example: ['1' => 'Adidas', '2' => 'Nike', '3' => 'New Balance;];
{{ Form::select('brand_id', $brands) }}
Also, you can simplify your error class using a ternary statement, something like this.
<div class="form-group {{ $errors->has('brand_id') ? 'has-error' : null }}">
Related
I am insert data product with images in dashboard, when I try to order the product I have error 404 not found and the URL showing value database in table like http://127.0.0.1:8000/shops/order/[%7B%22id%22:2,%22category_id%22:1,%22name_product%22:%22asdasd%22,%22harga%22:123123123,%22image%22:%22product-images//HapOzHmJPim1kIfmIeCM21xesCnIbR5Z7lpzcO8M.jpg%22,%22published_at%22:null,%22created_at%22:%222022-05-23T16:25:00.000000Z%22,%22updated_at%22:%222022-05-23T16:25:10.000000Z%22,%22kategori%22:%7B%22id%22:1,%22name_category%22:%22Top%22,%22created_at%22:%222022-05-23T16:22:40.000000Z%22,%22updated_at%22:%222022-05-23T16:22:40.000000Z%22%7D%7D].
But when I am insert data product without images in dashboard, and then I try to order the product is successful.
This is my route
Route::post('/shops/order/{shop:id}', [OrderController::class, 'store']);
This is OrderController
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Order;
use App\Models\User;
use App\Models\Shop;
class OrderController extends Controller
{
public function store(Request $request)
{
$createOrder = $request->validate([
'user_id' => 'required',
'name_product_id' => 'required',
'size' => 'required',
'no' => 'required',
'address' => 'required'
]);
Order::create($createOrder);
return redirect('shops/order/{shop:id}')->with('success', 'Order is successfully!');
}
}
This is my views
#extends('layouts.main')
#section('container')
<div class="container">
<div class="row mt-5">
#foreach ($shops as $shop)
<div class="card mb-3">
<div class="row g-0">
<div class="col-md-4">
<img src="{{ asset('storage/' . $shop->image) }}" alt="{{ $shop->name_product }}" class="img-fluid rounded-start" style="max-height: 400px; overflow:hidden">
</div>
<div class="col-md-8">
<div class="card-body">
<h5 class="card-title">{{ $shop->name_product }}</h5>
<p>Jenis {{ $shop->category->name_category }}</p>
<p class="card-text fw-bold">Rp.{{ $shop->price }}</p>
</div>
</div>
</div>
</div>
#endforeach
</div>
<div class="row mt-5">
<div class="col align-self-center">
#if (session()->has('success'))
<div class="alert alert-success text-center" role="alert">
{{ session('success') }}
</div>
#endif
</div>
</div>
<form method="POST" action="/shops/order/{{ $shops }}" class="row g-2" enctype="multipart/form-data">
#csrf
<h3 class="text-center mt-2">Detail Delivery</h3>
<div class="col-md-6">
<div class="mb-3">
<select class="form-select" name="user_id" hidden>
#foreach ($users as $name)
<option value="{{ $name->id }}">{{ $name->id }}</option>
#endforeach
</select>
</div>
<div class="mb-3">
<select class="form-select" name="name_produk_id" hidden>
#foreach ($shops as $shops_id)
<option value="{{ $shops_id->id }}">{{ $shops_id->id }}</option>
#endforeach
</select>
</div>
<div class="mb-3">
<label for="address" class="form-label">Address</label>
<textarea class="form-control" #error('address') is-invalid #enderror id="address" name="address" required>
</textarea>
</div>
</div>
<div class="col-md-4">
<label for="size" class="form-label mt-3">Select size :</label>
<select class="form-select" name="size">
<option selected>S</option>
<option value="M">M</option>
<option value="L">L</option>
<option value="XL">XL</option>
</select>
<div class="mt-3">
<label for="no" class="form-label">Nomor Whatsapp</label>
<input class="form-control" #error('no') is-invalid #enderror id="no" name="no" required autofocus">
</div>
<button type="submit" class="btn btn-primary mt-5">Buy Now</button>
</div>
</form>
</div>
#endsection
I am starting with Laravel 5.5.
I have an error when trying to send the data to the edit form:
`Illegal string offset 'name' (View: C: \ xampp \ htdocs \ laravel-ads \ resources \ views \ admin \ edit.blade.php)
public function edit($id)
{
//
$user = User::findOrFail($id);
//var_dump($user['name']);
return view('admin.edit', compact('user'));
}
<div class="container">
<h1 class="text center">Editor de Usuario</h1>
{!! Form::model($user, ['method' => 'PATCH', 'action' => ['AdminController#update', $user->id], 'files' => true]) !!}
<div class="form-group">
{!! Form::label('id', 'Id') !!}
{!! Form::number('id', '', ['class' => 'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('id_rol', 'Rol') !!}
{!! Form::number('id_rol', '', ['class' => 'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('imagen', 'Imagen') !!}
{!! Form::file('imagen', '', ['class' => 'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('name', 'Nombre') !!}
{!! Form::text('name', '', ['class' => 'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('email', 'Email') !!}
{!! Form::email('email', '', ['class' => 'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('password', 'Password') !!}
{!! Form::password('password', '', ['class' => 'form-control']) !!}
</div>
{!! Form::submit('Editar', ['class' => 'btn btn-success']) !!}
{!! Form::close() !!}
</div>
The route:
Route::resource('admin', 'AdminController');
My index.blade.php:
<div class="container-fluid"></div>
<h1 class="text-center"> Usuarios</h1>
<div class="table-responsive">
<table class="table table-dark">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Rol</th>
<th scope="col">Foto</th>
<th scope="col">Nombre</th>
<th scope="col">Email</th>
<th scope="col">Ultima actualizacion</th>
<th scope="col">Creado</th>
</tr>
</thead>
<tbody>
#foreach($users as $user)
<tr>
<th scope="row">{{$user->id}}</th>
<td>{{$user->id_rol}}</td>
<td><img src="images/{{$user->imagen}}" alt="imagen de usuario" width="150"></td>
<td> {{$user->name}}</td>
<td>{{$user->email}}</td>
<td>{{$user->updated_at}}</td>
<td>{{$user->created_at}}</td>
</tr>
#endforeach
</tbody>
</table>
</div>
</div>
The issue jumps in this place of Laravel:
* #param string $value
* #param array $options
*
* #return \Illuminate\Support\HtmlString
*/
public function input($type, $name, $value = null, $options = [])
{
$this->type = $type;
if (! isset($options['name'])) {
$options['name'] = $name;
}
// We will get the appropriate value for the given field. We will look for the
// value in the session for the value in the old input data then we'll look
// in the model instance if one is set. Otherwise we will just use empty.
$id = $this->getIdAttribute($name, $options);
if (! in_array($type, $this->skipValueTypes)) {
$value = $this->getValueAttribute($name, $value);
}
// Once we have the type, value, and ID we can merge them into the rest of the
// attributes array so we can convert them into their HTML attribute format
// when creating the HTML element. Then, we will return the entire input.
$merge = compact('type', 'value', 'id');
This answer no works to me
I have fixed the issue without discovering its cause.
I leave here the form that does work to see if any user can tell me where the error was.
I don't know what was wrong.
As a curious fact, the previous form even and everything being commented continued giving the issue.
<form method="POST" action="{{route('admin.update',$user->id)}}" enctype="multipart/form-data">
#csrf
#method('PUT')
<div class="form-group row">
<label for="name" class="col-md-4 col-form-label text-md-right">{{ __('Name') }}</label>
<div class="col-md-6">
<input id="name" type="text" class="form-control #error('name') is-invalid #enderror" name="name" value="{{ $user->name }}" autocomplete="name" autofocus>
#error('name')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="id_rol" class="col-md-4 col-form-label text-md-right">{{ __('Rol') }}</label>
<div class="col-md-6">
<input id="id_rol" type="number" class="form-control #error('id_rol') is-invalid #enderror" name="id_rol" value="{{ $user->id_rol }}" autocomplete="id_rol" autofocus>
#error('id_rol')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="email" class="col-md-4 col-form-label text-md-right">{{ __('E-Mail Address') }}</label>
<div class="col-md-6">
<input id="email" type="email" class="form-control #error('email') is-invalid #enderror" name="email" value="{{ $user->email }}" autocomplete="email">
#error('email')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<img class="col-md-4 col-form-label text-md-right" src="../../../public/images/{{$user->imagen}}" alt="imagen de usuario" width="150">
<div class="col-md-6">
<input id="imagen" type="file" class="form-control #error('imagen') is-invalid #enderror" name="imagen" value="{{ $user->imagen }}" autocomplete="imagen">
#error('imagen')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
<div class="col-md-2">
<button type="submit" class="btn btn-primary">
{{ __('Guardar') }}
</button>
</div>
</div>
</form>
)
I have been struggling with a form for my Laravel App....
I have 3 fields which are checkboxes and therefore is getting POSTed as arrays and then I have a textarea field and somehow SOMETIMES one of the 3 checkbox inputs get flooded with data from the textarea input field... It is very weird and only happens sometime and therefore I get a data to long truncated error in the database...
But I DD the input at the $request level and can see already there the array from the checkbox is flooded with the data from the textarea field... I can not wrap my head around why this is, as it's only sometimes...
And I can even get the error and go back a page in the browser and submit again with all the same data and then it can be working.. WHAT can cause this weird behavioer
This is my Laravel blade where the form is
#extends('layouts.app')
#section('head')
#endsection
#section('content')
#php
// dd($errors);
#endphp
<h2 class="page-title">Opret Artist Side</h2>
<div class="artist-box">
<form class="formgrid" method="POST" action="{{ route('artist.store') }}">
#csrf
<div class="formleft">
<label for="artist_name" class="label">Artist navn</label>
<input type="text" id="artist_name" name="artist_name" class="formitem #error('artist_name') is-invalid #enderror" value="{{ old('artist_name', $post->artist_name ?? null) }}" />
#error('artist_name')
<div class="invalid-feedback">
#foreach($errors->get('artist_name') as $error)
{{ $error }}
#endforeach
</div>
#else
<small class="text-muted form-text" id="artist_name_help">Jeres band/artist navn. <span class="text-danger">OBS! Kan IKKE ændres</span></small>
#enderror
</div>
<div class="formright">
<label for="contact_person" class="label">Kontakt person</label>
<input type="text" name="contact_person" id="contact_person" class="formitem #error('contact_person') is-invalid #enderror" value="{{ old('contact_person', $post->content ?? null) }}" />
#error('contact_person')
<div class="invalid-feedback">
#foreach($errors->get('contact_person') as $error)
{{ $error }}
#endforeach
</div>
#else
<small class="text-muted form-text" id="contact_person_help">Kontakt persons navn</small>
#enderror
</div>
<div class="formleft">
<label for="email" class="label">Email</label>
<input type="text" name="email" id="email" class="formitem #error('email') is-invalid #enderror" value="{{ old('email', $post->email ?? null) }}" />
#error('email')
<div class="invalid-feedback">
#foreach($errors->get('email') as $error)
{{ $error }}
#endforeach
</div>
#else
<small class="text-muted form-text" id="email_help">Kontakt email</small>
#enderror
</div>
<div class="formright">
<label for="phone" class="label">Tlf nummer</label>
<input type="text" name="phone" id="phone" class="formitem #error('phone') is-invalid #enderror" value="{{ old('phone', $post->phone ?? null) }}" />
#error('phone')
<div class="invalid-feedback">
#foreach($errors->get('phone') as $error)
{{ $error }}
#endforeach
</div>
#else
<small class="text-muted form-text" id="phone_help">Kontakt tlf nummer</small>
#enderror
</div>
<div class="formleft">
<label for="hometown" class="label">Hjemby</label>
<input type="text" name="hometown" id="hometown" class="formitem #error('hometown') is-invalid #enderror" value="{{ old('hometown', $post->hometown ?? null) }}" />
#error('hometown')
<div class="invalid-feedback">
#foreach($errors->get('hometown') as $error)
{{ $error }}
#endforeach
</div>
#else
<small class="text-muted form-text" id="hometown_help">Jeres Hjemby</small>
#enderror
</div>
<div class="formright">
<label for="category" class="label">Kategori</label>
<select name="category" id="category" class="formitem #error('category') is-invalid #enderror">
{{-- Show a non selectable if with info of none selected --}}
#if(old('category') === null)
<option disabled="disabled" selected value="null">Vælg en kategori</option>
#endif
#foreach($categories as $category)
<option #if(old('category') !== null && old('category') == $category->id) selected #endif value="{{ $category->id }}"
>{{ $category->artist_category }}</option>
#endforeach
</select>
#error('category')
<div class="invalid-feedback">
#foreach($errors->get('category') as $error)
{{ $error }}
#endforeach
</div>
#else
<small class="text-muted form-text" id="">Hvilken kategori hører i under</small>
#enderror
</div>
<div class="formfull">
<label for="budget" class="label">Budget i spiller for</label>
<ul class="ks-cboxtags">
#foreach($budgets as $budget)
{{-- <div class="form-check form-check-inline"> --}}
<li><input #if(old('budget') !== null && in_array($budget->id,old('budget'))) checked #endif
type="checkbox" name="budget[]" id="budget{{ $budget->id }}" class="form-check-input #error('budget') is-invalid #enderror" value="{{ $budget->id }}" />
<label class="form-check-label" for="budget{{ $budget->id }}">{{ $budget->artist_budget }}</label></li>
{{-- </div> --}}
#endforeach
</ul>
#error('budget')
<div class="invalid-feedback d-block">
#foreach($errors->get('budget') as $error)
{{ $error }}
#endforeach
</div>
#else
<small class="text-muted form-text" id="budget_help">Vælg hvilket budget i optræder for, gerne flere</small>
#enderror
</div>
{{-- --}}
<div class="formfull">
<label for="genres" class="label">Genre</label>
<ul class="ks-cboxtags">
#foreach($genres as $genre)
{{-- <div class="form-check form-check-inline"> --}}
<li><input #if(old('genres') !== null && in_array($genre->id,old('genres'))) checked #endif
type="checkbox" name="genres[]" id="genres{{ $genre->id }}" value="{{ $genre->id }}" class="form-check-input #error('genres') is-invalid #enderror" />
<label class="form-check-label" for="genres{{ $genre->id }}">{{ $genre->genre }}</label></li>
{{-- </div> --}}
#endforeach
</ul>
#error('genres')
<div class="invalid-feedback d-block">
#foreach($errors->get('genres') as $error)
{{ $error }}
#endforeach
</div>
#else
<small class="text-muted form-text" id="">Hvike genrer hører i under</small>
#enderror
</div>
{{-- --}}
<div class="formfull">
<label for="area" class="label">Områder hvor i optræder</label>
<ul class="ks-cboxtags">
#foreach($areas as $area)
{{-- <div class="form-check form-check-inline"> --}}
<li><input #if(old('area') !== null && in_array($area->id,old('area'))) checked #endif
type="checkbox" name="area[]" id="area{{ $area->id }}" value="{{ $area->id }}" class="form-check-input #error('area') is-invalid #enderror" />
<label class="form-check-label" for="area{{ $area->id }}">{{ $area->artist_area }}</label></li>
{{-- </div> --}}
#endforeach
</ul>
#error('area')
<div class="invalid-feedback d-block">
#foreach($errors->get('area') as $error)
{{ $error }}
#endforeach
</div>
#else
<small class="text-muted form-text" id="">Vælg hvilke områder i optræder i</small>
#enderror
</div>
<div class="formleft">
<label for="desc" class="label">Beskriv jer selv</label>
<textarea name="description" id="description" class="formitem #error('description') is-invalid #enderror">{{ old('description', $post->description ?? null) }}</textarea>
{{-- <input id="description" value="{{ old('description', $post->description ?? null) }}" class="form-control #error('description') is-invalid #enderror" name="description" type="hidden">
#trix(\App\ArtistPage::class, 'trixinput',
[
'id' => 'description',
// 'class' => 'form-control',
'hideTools' => ['file-tools'],
'hideButtonIcons' => ['attach', 'link', 'code', 'strike', 'heading-1']
]) --}}
{{-- <input id="desc" value="{{ old('description', $post->description ?? null) }}" type="hidden" name="description">
<trix-editor input="desc" class="#error('description') is-invalid #enderror"></trix-editor> --}}
#error('description')
<div class="invalid-feedback">
#foreach($errors->get('description') as $error)
{{ $error }}
#endforeach
</div>
#else
<small class="text-muted form-text" id="description_help">Giv en god beskrivelse af jer selv og hvad i tilbyder<br>
Tilladte tags er <strong>{{ '<br><b><i><li><ul><ol><hr><strong><p>' }}</strong>
</small>
#enderror
</div>
<button type="submit" class="btn btn-primary">Opret</button>
</form>
</div>
#endsection
See also this image of the DD dump on the $request
Hmmmm Think I figured it out :-)
But it has been such a sporadic bug so I'm not sure yet... But seems like it has gone away :-)
Seems like it was this value line on each field I have gotten messed up
The value line structure on the input fields I had was
value="{{ old('artist_name', $post->artist_name ?? null) }}"
And it should be
value="{{ old('artist_name') ?? $post->artist_name ?? null }}"
Dont know why I ended up with such an obscure Value part on every input field :-)
But sometimes the eyes just gets blind on code :-)
I want to save question_id in answer table using post form
I tried to use foreach or functions but i always got null data
Controller
public function store(Request $request, Survey $survey)
{
$request->validate([
'answer' => 'required',
]);
$survey->option_name = unserialize($survey->option_name);
$answers = new Answer([
'answer' => $request->get('answer'),
'commentaire' => $request->get('commentaire'),
'user_id' => auth()->id(),
'last_ip' => request()->ip(),
'question_id' => $survey->questions,
'survey_id' => $survey->id,
]);
$answers->save();
return redirect()->action('SurveyController#view_survey_answers', [$survey->id]);
}
answers table
question table's row :
id
survey_id
title
timestamp
I got always null data or i tried using where but i got errors like id index doesn't exists...
View :
{!! Form::open(array('action'=>array('AnswerController#store', $survey->id))) !!}
#forelse ($survey->questions as $key=>$question)
<p class="flow-text">Question {{ $key+1 }} - {{ $question->title }}</p>
#if($question->question_type === 'text')
<div class="form-group">
<div class="input-field col s12">
<input id="answer" type="text" name="answer">
<label for="answer">Answer</label>
</div>
</div>
#elseif($question->question_type === 'textarea')
<div class="form-group">
<div class="input-field col s12">
<textarea id="textarea1" class="materialize-textarea" name="{{ $question->id }}[answer]"></textarea>
<label for="textarea1">Textarea</label>
</div>
</div>
#elseif($question->question_type === 'radio')
#foreach($question->option_name as $key=>$value)
<p style="margin:0px; padding:0px;">
#if($value === 'else')
<div class="form-group" style="margin-left: 20px;">
<input name="answer" class="custom-control-input" type="radio" id="{{ $value }}" value="{{$value}}"/>
<label class="custom-control-label" for="{{ $value }}">{{ $value }}</label>
<div id="textboxes" style="display: none">
<br>
<textarea class="form-control" name="commentaire" id="exampleFormControlTextarea1" rows="3" placeholder="Write a large text here ..."></textarea>
</div>
</div>
#else
<p style="margin:0px; padding:0px;">
<div class="form-group" style="margin-left: 20px;">
<input name="answer" class="custom-control-input" type="radio" id="{{ $value }}" value="{{ $value}}"/>
<label class="custom-control-label" for="{{ $value }}">{{ $value }}</label>
</div>
</p>
#endif
#endforeach
#elseif($question->question_type === 'checkbox')
#foreach($question->option_name as $key=>$value)
<p style="margin:0px; padding:0px;">
<div class="form-group">
<input type="checkbox" id="{{ $value }}" name="answer" value="{{$value}}"/>
<label for="{{$value}}">{{ $value }}</label>
</div>
</p>
#endforeach
#endif
<div class="divider" style="margin:10px 10px;"></div>
#empty
<span class='flow-text center-align'>Nothing to show</span>
#endempty
<div class="form-group">
{{ Form::submit('Submit Survey', array('class'=>'btn btn-success mt-4')) }}
</div>
{!! Form::close() !!}
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? :)