LaravelCollective does not receive the data - laravel-5

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>

Related

Method App\Http\Livewire\Product::extension does not exist

I am learning laravel livewire, and this is my first time using livewire.
I am having trouble running my code on Laravel 8 with laravel-livewire. When I click submit always showing an error like that.
I'm don't know what's wrong and how to fix this
web.php
<?php
use Illuminate\Support\Facades\Route;
use App\Http\Livewire\Product;
Route::get('/products', Product::class);
Controller
<?php
namespace App\Http\Livewire;
use Livewire\Component;
use Livewire\WithFileUploads;
use App\Models\Product as ProductModel;
use Illuminate\Support\Facades\Storage;
class Product extends Component
{
use WithFileUploads;
public $name, $image, $description, $qty, $price;
public function previewImage()
{
$this->validate([
'image' => 'image|max:2048'
]);
}
public function store()
{
$this->validate([
'name' => 'required',
'image' => 'image|max:2048|required',
'description' => 'required',
'qty' => 'required',
'price' => 'required',
]);
$imageName = md5($this->image.microtime().'.'. $this->extension());
Storage::putFileAs(
'public/images',
$this->image,
$imageName
);
ProductModel::create([
'name' => $this->name,
'image' => $imageName,
'description' => $this->description,
'qty' => $this->qty,
'price' => $this->price
]);
session()->flash('info', 'Product created sSccessfully');
$this->name = '';
$this->image = '';
$this->description = '';
$this->qty = '';
$this->price = '';
}
}
In this is my blade code, i hope someone can help me. Thanks
<div>
<div class="row">
<div class="col-md-8">
<div class="card">
<div class="card-body">
<h2 class="font-weight-bold mb-3">Product List</h2>
<table class="table table-bordered table-hover table-striped">
<thead>
<tr>
<th>No</th>
<th>Name</th>
<th>Image</th>
<th>Description</th>
<th>Qty</th>
<th>Price</th>
</tr>
</thead>
<tbody>
#foreach($products as $index=>$product)
<tr>
<td>{{ $index+1 }}</td>
<td>{{ $product->name }}</td>
<td>{{ $product->image }}</td>
<td>{{ $product->description }}</td>
<td>{{ $product->qty }}</td>
<td>{{ $product->price }}</td>
</tr>
#endforeach
</tbody>
</table>
</div>
</div>
</div>
<div class="col-md-4">
<div class="card">
<div class="card-body">
<h2 class="font-weight-bold mb-3">Create Product</h2>
<form wire:submit.prevent="store">
<div class="form-group">
<label>Product Name</label>
<input wire:model="name" type="text" class="form-control">
#error('name') <small class="text-danger">{{ $message }}</small> #enderror
</div>
<div class="form-group">
<label>Product Image</label>
<div class="custom-file">
<input wire:model="image" type="file" class="custom-file-input" id="customFile">
<label for="customFile" class="custom-file-label">Choose Image</label>
</div>
#error('image') <small class="text-danger">{{ $message }}</small> #enderror
</div>
#if($image)
<label class="mt-2">Image Preview</label>
<img src="{{ $image->temporaryUrl() }}" class="img-fluid" alt="Preview Image">
#endif
<div class="form-group">
<label>Description</label>
<textarea wire:model="description" class="form-control"></textarea>
#error('description') <small class="text-danger">{{ $message }}</small> #enderror
</div>
<div class="form-group">
<label>Qty</label>
<input wire:model="qty" type="number" class="form-control">
#error('qty') <small class="text-danger">{{ $message }}</small> #enderror
</div>
<div class="form-group">
<label>Price</label>
<input wire:model="price" type="number" class="form-control">
#error('price') <small class="text-danger">{{ $message }}</small> #enderror
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary btn-block">Submit Product</button>
</div>
</form>
</div>
</div>
<div class="card mt-3">
<div class="card-body">
<h3>{{ $name }}</h3>
<h3>{{ $image }}</h3>
<h3>{{ $description }}</h3>
<h3>{{ $qty }}</h3>
<h3>{{ $price }}</h3>
</div>
</div>
</div>
</div>
use $this->image->extension() or \File::extension($this->image);
instead of $this->extensionin your code
$imageName = md5($this->image.microtime().'.'. $this->extension());
extension() is a method of FIle class thus needs a instance of Symfony\Component\HttpFoundation\File\UploadedFile class

Laravel dont work method if i have 2 in 1 blade

I have 2 method in 1 blade, Delete and PUT, if i want delete it's work, but if I save info updated and I use method PUT, drop error: The DELETE method is not supported for this route. Supported methods: GET, HEAD, PUT., I use form collective composer for form.
SAVE Button not working, drop error, Remove button working good.
<div class="container-fluid mt--7">
<div class="row">
<div class="col-xl-12">
{!! Form::open(['action' => ['InvoiceController#update', $invoice->id], 'method' => 'POST']) !!}
{{csrf_field()}}
<div class="card bg-secondary shadow">
<div class="card-header bg-white border-0">
<div class="row align-items-center">
<div class="col-8">
<h3 class="mb-0">Edit {{$invoice->number}} invoice </h3>
</div>
<div class="col-4 text-right">
{{ Form::submit('Save', ['class' => 'btn btn-sm btn-primary']) }}
{{ Form::hidden('_method', 'PUT') }}
</div>
</div>
</div>
<div class="card-body">
<div class="pl-lg-4">
<div class="row">
<div class="col-lg-4">
<div class="form-group">
<label class="form-control-label">Company</label>
<select class="form-control form-control-alternative" name="company_id" required>
<option value="{{$invoice->company_id}}" selected>{{ $invoice->company_name->Name }}</option>
#foreach($companys as $company)
<option value="{{$company->id}}">{{ $company->Name }}</option>
#endforeach
</select>
</div>
</div>
<div class="col-lg-4">
<div class="form-group">
<label class="form-control-label">Payment</label>
<select class="form-control form-control-alternative" name="payment" required>
<option value="{{$invoice->payment}}" selected>{{$invoice->payment}}</option>
<option value="Pending">Pending</option>
<option value="Paid">Paid</option>
<option value="Canceled">Canceled</option>
</select>
</div>
</div>
<div class="col-lg-4">
<div class="form-group">
<label class="form-control-label">Invoices number</label>
<input class="form-control form-control-alternative" type="text" value="{{$invoice->number}}" disabled>
<input class="form-control form-control-alternative" name="number" placeholder="Auto generated" type="text" value="{{$invoice->number}}" hidden>
</div>
</div>
</div>
<div class="row">
<div class="col-lg-6">
<div class="form-group">
<label class="form-control-label">Date</label>
<input class="form-control form-control-alternative datepicker-here" name="date" data-language='en' placeholder="Select date" type="text" value="{{$invoice->date}}">
</div>
</div>
<div class="col-lg-6">
<div class="form-group">
<label class="form-control-label">Due date</label>
<input class="form-control form-control-alternative datepicker-here" name="due_date" data-language='en' placeholder="Select date" type="text" value="{{$invoice->due_date}}">
</div>
</div>
</div>
<hr class="my-4" />
<div class="row">
<div class="col-lg-12">
<table class="table table-bordered" id="dynamic_field">
<thead>
<tr>
<th scope="col">No.</th>
<th scope="col">Description</th>
<th scope="col">Qty</th>
<th scope="col">Price</th>
<th scope="col">Amount</th>
<th scope="col">Action</th>
</tr>
</thead>
<tbody>
#if(count($invoice_lists) > 0)
<?php $no = 1; ?>
#foreach( $invoice_lists as $invoice_list )
<tr>
<td>
{{ $no }}
<input type="text" name="list_id[]" value="{{ $invoice_list->id }}" hidden>
</td>
<td><input class="form-control form-control-alternative" type="text" name="description[]" value="{{$invoice_list->desc}}" placeholder="Description"></td>
<td><input class="form-control form-control-alternative qty" type="text" name="qty[]" value="{{$invoice_list->qty}}" placeholder="Qty"></td>
<td><input class="form-control form-control-alternative price" type="text" name="price[]" value="{{$invoice_list->price}}" placeholder="Price"></td>
<td><input class="form-control form-control-alternative amount" type="text" name="amount[]" value="{{$invoice_list->amount}}" placeholder="Amount"></td>
<td>
#if ($no == 1)
{!! Form::open(['action' => ['InvoiceController#remove', $invoice_list->id, $invoice->id], 'method' => 'POST']) !!}
{{ Form::hidden('_method', 'DELETE') }}
{{ Form::submit('Remove', ['class' => 'btn btn-danger btn-sm', 'disabled']) }}
{!! Form::close() !!}
#else
{!! Form::open(['action' => ['InvoiceController#remove', $invoice_list->id, $invoice->id], 'method' => 'POST']) !!}
{{ Form::hidden('_method', 'DELETE') }}
{{ Form::submit('Remove', ['class' => 'btn btn-danger btn-sm']) }}
{!! Form::close() !!}
#endif
</td>
<?php $no++; ?>
</tr>
#endforeach
#else
....
#endif
</tbody>
<thead>
<tr>
<th colspan="2"></th>
<th scope="col"><b>Sub Total</b></th>
<th scope="col"><b>VAT(21%)</b></th>
<th scope="col"><b>Grand Total</b></th>
</tr>
</thead>
<tbody>
<tr>
<th colspan="2"></th>
<td scope="col">
<input class="form-control form-control-alternative sub" value="{{$invoice->sub}}" disabled>
<input class="form-control form-control-alternative subhidden" name="subhidden" value="{{$invoice->sub}}" hidden>
</td>
<td scope="col">
<input class="form-control form-control-alternative vat" value="{{$invoice->vat}}" disabled>
<input class="form-control form-control-alternative vathidden" name="vathidden" value="{{$invoice->vat}}" hidden>
</td>
<td scope="col">
<input class="form-control form-control-alternative grand" value="{{$invoice->grand}}" disabled>
<input class="form-control form-control-alternative grandhidden" name="grandhidden" value="{{$invoice->grand}}" hidden>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<hr class="my-4" />
<div class="row">
<div class="col-lg-12">
<div class="form-group">
<label class="form-control-label">Terms and Conditions</label>
<textarea class="form-control form-control-alternative" name="terms" rows="5" placeholder="Terms and Conditinios" required>{{$invoice->terms}}</textarea>
</div>
</div>
</div>
<input type="text" name="id" value="{{$invoice->id}}" hidden>
</div>
</div>
</div>
{!! Form::close() !!}
</div>
</div>
</div>
You have multiple forms in 1 form, this is not actually good idea, but if it is critically required to have so, you have to give unique id attribute to each form and also set form="currentFormId" to the form's inputs

Laravel save related data in database

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() !!}

Laravel multiple insert in a table

I want to create a post and be able to add different categories, so I made this code
public function store(Request $request)
{
$this->validate($request,[
'title' => 'required',
'body' => 'required',
'name'=>'required'
]);
$post = new \App\Post([
'title' => $request->get('title'),
'body' => $request->get('body')
]);
$post->save();
foreach ($request->name as $data) {
$categories = new \App\Category();
$categories->name = $request->get('name');
//dd($categories);
$post->categories()->save($categories);
}
return redirect()->route('create');
}
model Post
public function categories(){return $this->hasMany(\App\Category::class, 'post_id');}
model Category
public function something(){return $this->belongsTo(\App\Solicitud::class, 'post_id');}
HTML
<form class="form-horizontal" role="form" method="POST" action="{{ route('store_data') }}">
{{ csrf_field() }}
<div class="form-group{{ $errors->has('title') ? ' has-error' : '' }}">
<label for="title" class="col-md-4 control-label">title:</label>
<div class="col-md-6">
<input type="text" name="title" placeholder="Cantidad" class="form-control" value="{{ old('title') }}" />
#if ($errors->has('title'))
<span class="help-block">
<strong>{{ $errors->first('title') }}</strong>
</span>
#endif
</div>
</div>
<div class="form-group{{ $errors->has('body') ? ' has-error' : '' }}">
<label for="body" class="col-md-4 control-label">Body:</label>
<div class="col-md-6">
<input type="text" name="body" placeholder="Cantidad" class="form-control" value="{{ old('body') }}" />
#if ($errors->has('body'))
<span class="help-block">
<strong>{{ $errors->first('body') }}</strong>
</span>
#endif
</div>
</div>
<div class="form-group{{ $errors->has('name') ? ' has-error' : '' }}">
<table class="table table-bordered" id="dynamic_field">
<thead>
<tr>
</tr>
</thead>
<tbody>
<tr>
<td><input type="text" name="name[]" placeholder="Name" class="form-control name_list" value="{{ old('name') }}" /></td>
<td><button type="button" name="add" id="add" class="btn btn-success"> + </button></td>
</tr>
</tbody>
</table>
</div>
<div class="form-group">
<div class="col-md-6 col-md-offset-4">
<button type="submit" class="btn btn-primary">
Create
</button>
</div>
<div class="col-md-6 col-md-offset-4">
<a class="btn btn-info" href="{{ URL::previous() }}">back</a> <br>
</div>
</div>
</form>
Scritps :
<script>
$(document).ready(function(){
var i=1;
$('#add').click(function(){
i++;
$('#dynamic_field').append('<tr id="row'+i+'"><td><input type="text" name="name[]" placeholder="Name" class="form-control name_list" /></td><td><button type="button" name="remove" id="'+i+'" class="btn btn-danger btn_remove">-</button></td></tr>');
});
$(document).on('click', '.btn_remove', function(){
var button_id = $(this).attr("id");
$('#row'+button_id+'').remove();
});
});
</script>
but I get this error. when I submit the form
Type error: Argument 1 passed to Illuminate\Database\Grammar::parameterize() must be of the type array, integer given, called in C:\xampp\htdocs\proyect\vendor\laravel\framework\src\Illuminate\Database\Query\Grammars\Grammar.php on line 681.
"Type error: Argument 1 passed to Illuminate\Database\Grammar::parameterize() must be of the type array, integer given, called in C:\xampp\htdocs\proyect\vendor\ ▶"
and if press submit with the input empty I get this error
htmlspecialchars() expects parameter 1 to be string, array given (View: C:\xampp\htdocs\proyect\resources\views\create.blade.php)
but if I edit the code, in this way it works but adds only one category.
$categories = new \App\Category();
$categories->name = $request->get('name');
//dd($categories);
$post->categories()->save($categories);
I hope I have explained well and thanks :)

create a Select Box form From Database in Laravel

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 }}">

Resources