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? :)
Related
Having two dropdownmenu, choosing days and times inserted manually from sql. What is the best method of show at shopping cart which day and time the user chosen and added to the shopping cart.
my idea is under below.
index.blade.php
#extends('layouts.master')
#section('title')
Shopping Cart
#endsection
#section('content')
#foreach($products->chunk(3) as $productsChunk)
<div class="row">
#foreach($productsChunk as $products)
<div class="col-sm-4 col-md-4">
<div class="thumbnail">
<img src="{{ $products->imagePath }}" alt="..." class="img-responsive">
<div class="caption">
<h3>{{ $products->title }}</h3>
<p class="description">{{ $products->description }}</p>
<div class="clearfix">
<script type="text/javascript">
<div class="container">
<h2>Laravel Dependent Dropdown</h2>
<div class="form-group">
<label for="day">Select Day:</label>
<select name1="day" class="form-control" style="width:250px">
<option value="">--- Select Day ---</option>
#foreach ($days as $key => $value)
<option value="{{ $key }}">{{ $value }}</option>
#endforeach
</select>
</div>
<div class="form-group">
<label for="time">Select Time:</label>
<select name1="time" class="form-control"style="width:150px">
<option>--Time--</option>
#foreach ($times as $key => $value)
<option value="{{ $key }}"{{ ( $key == $selectedID) ? 'selected' : '' }}>{{ $value }}</option>
#endforeach
</select>
</select>
</div>
</div>
<script type="text/javascript">
jQuery(document).ready(function ()
{
jQuery('select[name1="day"]').on('change',function(){
var dayID = jQuery(this).val();
if(dayID)
{
jQuery.ajax({
url : 'shopindex/getindex/' +dayId,
type : "GET",
dataType : "json",
success:function(data)
{
console.log(data);
jQuery('select[name1="day"]').empty();
jQuery.each(data, function(key,value){
$('select[name1="day"]').append('<option value="'+ key +'">'+ value +'</option>');
});
}
});
}
else
{
$('select[name1="day"]').empty();
}
});
});
</script>
<div class="container">
<div class="form-group">
<label for="days">Select Day:</label>
<select name1="day" class="form-control" style="width:250px">
<option value="">--- Select Day ---</option>
#foreach ($days as $key => $value)
<option value="{{ $key }}">{{ $value }}</option>
#endforeach
</select>
</div>
<div class="form-group">
<label for="time">Select Time:</label>
<select name2="time" class="form-control"style="width:250px">
<option value="">--Time--</option>
#foreach ($times as $key => $value)
<option value="{{ $key }}">{{ $value }}</option>
#endforeach
</select>
</div>
</div>
<script type="text/javascript">
jQuery(document).ready(function ()
{
jQuery('select[name1="time"]').on('change',function(){
var dayID = jQuery(this).val();
if(dayID)
{
jQuery.ajax({
url : 'shopindex/getindex/' +dayID,
type : "GET",
dataType : "json",
success:function(data)
{
console.log(data);
jQuery('select[name2="time"]').empty();
jQuery.each(data, function(key,value){
$('select[name2="time"]').append('<option value="'+ key +'">'+ value +'</option>');
});
}
});
}
else
{
$('select[name2="time"]').empty();
}
});
});
</script>
<div class="pull-left price">${{ $products->price }}</div>
<a href="{{ route('product.addToCart', ['id' => $products->id]) }}"
class="btn btn-success pull-right" role="button">Add to cart</a>
</div>
</div>
</div>
</div>
#endforeach
</div>
#endforeach
#endsection
ProductController.php
public function getIndex()
{
$products = Product::all();
$days = DB::table('days')->pluck("name1","id");
$times = DB::table('times')->pluck("name2","id");
return view('shop.index',compact('products','days','times'), ['products' => $products]);
}
shopping-cart.blade.php
#section('content')
#if(Session::has('cart'))
<div class="container-fluid">
<div class="row">
<div class="col-md-6 m-auto">
#foreach ($products as $product)
<li class="list-group-item">
<img src="{{ $product['item']['imagePath'] }}" height="120" width="100">
<span class="badge badge-secondary">Quantity: {{ $product['qty'] }}</span>
<span class="badge badge-secondary">Item: {{ $product['item']['title'] }}</span>
<span class="badge badge-secondary">Item: {{ $product['item']['day'] }}</span>
<span class="badge badge-secondary">Item: {{ $product['item']['time'] }}</span>
<span class="badge badge-secondary">Price: ${{ $product['price'] }}</span>
<div class="btn-group">
<button type="button" class="btn btn-primary btn-md dropdown-toggle" data-toggle="dropdown">Action
<span class="caret"></span></button>
<ul class="dropdown-menu">
<li>Reduce by 1
</li>
<li>Reduce All</li>
</ul>
</div>
</li>
#endforeach
</ul>
</div>
</div>
</div>
<div class="container-fluid">
<div class="row">
<div class="col-md-4 m-auto">
<strong>Total Cost: ${{ $totalPrice }}</strong>
</ul>
</div>
</div>
</div>
<hr>
<div class="container-fluid">
<div class="row">
<div class="col-md-4 m-auto">
<button>Checkout</button>
</div>
</div>
</div>
#else
<div class="container-fluid">
<div class="row">
<div class="col-md-4 m-auto">
<h1>No item to cart</h1>
</ul>
</div>
</div>
</div>
#endif
#endsection
my idea at index.blade.php
<select name2="time" class="form-control"style="width:250px">
<option value="">--Time--</option>
#foreach ($times as $key => $value)
<option value="{{ $key }}"{{ ( $key == $times_id) ? 'selected' : '' }}>{{ $value }}</option>
#endforeach
</select>
but $times_id is undefined
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'm setting up a new project to perform multi language form but i'm stuck in edit form i don't know how to handle that
I created my controller and create view the only thing i need is edit view
so you can check my create view in bellow that work fine :
<div class="card-body text-center">
{!! Form::open(['route' => 'content.store', 'method' => 'Post']) !!}
<div class="card">
<div class="card-body">
<div class="form-group">
<label class="mx-4" for="my-input">{{ __('content/form.country_t') }}:</label>
<input id="my-input " type="text" name="country" placeholder="{{ __('content/form.country') }}">
<label class="mx-4" for="my-input">{{ __('content/form.city_t') }}:</label>
<input id="my-input" type="text" name="city" placeholder="{{ __('content/form.city') }}">
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="card col-xs-12 p-0">
<nav>
<div class="nav nav-pills nav-fill card-header" id="nav-tab" role="tablist">
#foreach (config('translatable.locales') as $la=>$desc)
<a class="nav-item nav-link" id="nav-home-tab" data-toggle="tab" href="#{{ $la }}" role="tab" aria-controls="nav-home" aria-selected="true">{{ $desc }}</a> #endforeach
</div>
<div class="tab-content py-3 px-3 px-sm-0 card-body" id="nav-tabContent">
#foreach (config('translatable.locales') as $la=>$desc)
<div class="tab-pane fade px-4" id="{{ $la }}" role="tabpanel" aria-labelledby="nav-home-tab">
<div class="form-group">
<label for="my-input" class="">{{ __('content/form.title') }}</label>
<input id="my-input" class="form-control" type="text" name="translations[{{ $la }}][title]">
</div>
<div class="form-group">
<label for="my-input" class="">{{ __('content/form.body') }}</label>
<input id="my-input" class="form-control" type="text" name="translations[{{ $la }}][body]">
</div>
</div>
#endforeach
</div>
</nav>
</div>
<button type="submit" class="row col-12 mt-2 mx-auto btn btn-primary">{{ __('content/form.submit') }}</button>
</div>
</div>
</div>
</div>
{!! Form::close() !!}
</div>
and this is my controller :
public function store(Request $request)
{
$contents = new Content;
// $contents->fill($request->all());
$this->fillRequest($request,$contents);
$contents->User()->associate(\Auth::user());
$contents->saveOrFail();
return redirect()->route('content.index')->with('success','با موفقیت ساخته شد');
}
private function fillRequest(Request $request, Content $model)
{
//fill model on fillable variables
$model->fill($request->only($model->getFillable()));
$model->saveOrFail();
foreach ($request->translations as $la => $desc) {
//if title field is null ignore the translations
// in case of there is a translation... delete it
if (!$desc["title"]) {
if ($model->hasTranslation($la)) {
$model->deleteTranslations($la);
}
continue;
}
//create new translation if not exists
$model->translateOrNew($la)->fill($desc);
$model->saveOrFail();
}
return $model;
}
I need to know how can i create edit view exactly same as my create view above
I try to make a page index.blade, but i getting error
Undefined variable: title (View: C:\xampp\htdocs\myproject\resources\views\categories\index.blade.php)
I am using laravel 5.4 PHP 7.0.33
Is there anything wrong with the code?
My Controller
<?php
namespace App\Http\Controllers;
use App\Category;
use Illuminate\Http\Request;
class CategoryController extends Controller
{
/**
* Display a listing of the resource.
*
* #return \Illuminate\Http\Response
*/
public function index()
{
$categories = Category::orderBy('created_at', 'DESC')->paginate(10);
return view('categories.index', compact('categories'));//
}
My index.blade
this is my view/categories/index.blade.php
#extends('layout.master')
#section('title')
<title>Manajemen Kategori</title>
#endsection
#section('content')
<div class="content-wrapper">
<div class="content-header">
<div class="container-fluid">
<div class="row mb-2">
<div class="col-sm-6">
<h1 class="m-0 text-dark">Manajemen Kategori</h1>
</div>
<div class="col-sm-6">
<ol class="breadcrumb float-sm-right">
<li class="breadcrumb-item">Home</li>
<li class="breadcrumb-item active">Kategori</li>
</ol>
</div>
</div>
</div>
</div>
<section class="content">
<div class="container-fluid">
<div class="row">
<div class="col-md-4">
#card
#slot('title')
<div class="card">
<div class="card-header with-border">
<h3 class="card-title">{{ $title }}</h3>
</div>
<div class="card-body">
{{ $slot }}
</div>
{{ $footer }}
</div>
#endslot
#if (session('error'))
#alert
<div class="alert alert-{{ $type }} alert-dismissible">
{{ $slot }}
</div>
#endalert
#endif
<form role="form" action="{{ route('kategori.store') }}" method="POST">
#csrf
<div class="form-group">
<label for="name">Kategori</label>
<input type="text"
name="name"
class="form-control {{ $errors->has('name') ? 'is-invalid':'' }}" id="name" required>
</div>
<div class="form-group">
<label for="description">Deskripsi</label>
<textarea name="description" id="description" cols="5" rows="5" class="form-control {{ $errors->has('description') ? 'is-invalid':'' }}"></textarea>
</div>
#slot('footer')
<div class="card-footer">
<button class="btn btn-primary">Simpan</button>
</div>
</form>
#endslot
#endcard
</div>
<div class="col-md-8">
#card
#slot('title')
List Kategori
#endslot
#if (session('success'))
#alert(['type' => 'success'])
{!! session('success') !!}
#endalert
#endif
<div class="table-responsive">
<table class="table table-hover">
<thead>
<tr>
<td>#</td>
<td>Kategori</td>
<td>Deskripsi</td>
<td>Aksi</td>
</tr>
</thead>
<tbody>
#php $no = 1; #endphp
#forelse ($categories as $row)
<tr>
<td>{{ $no++ }}</td>
<td>{{ $row->name }}</td>
<td>{{ $row->description }}</td>
<td>
<form action="{{ route('kategori.destroy', $row->id) }}" method="POST">
#csrf
<input type="hidden" name="_method" value="DELETE">
<i class="fa fa-edit"></i>
<button class="btn btn-danger btn-sm"><i class="fa fa-trash"></i></button>
</form>
</td>
</tr>
#empty
<tr>
<td colspan="4" class="text-center">Tidak ada data</td>
</tr>
#endforelse
</tbody>
</table>
</div>
#slot('footer')
#endslot
#endcard
</div>
</div>
</div>
</section>
</div>
#endsection
My route web.php
Route::resource('/kategori', 'CategoryController',
['except' => ['create', 'show']]);
It should be like this
public function index()
{
$categories = Category::orderBy('created_at', 'DESC')->paginate(10);
$title = ''; //your title
return view('categories.index', compact('categories','title'));
}
because title not getting value from controller.
You dont pass variable title to view
Add some like this:
$title = 'Your title';
return view('categories.index', compact('categories','title'));
If title is a field of Category
If title is a field/member of Category model, then you would do {{ $category->title }}. I think this is the real error.
Otherwise
You need to define and send the variable as other have said.
$tile='Your Title';
return view('categories.index', compact('categories','title'));
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 }}">