i found this error
Missing required parameters for [Route: roles.destroy] [URI: roles/{role}]. (View: E:\wamp64\www\student_system\resources\views\roles\table.blade.php)
<div class="table-responsive">
<table class="table" id="roles-table">
<thead>
<tr>
<th>Name</th>
<th colspan="3">Action</th>
</tr>
</thead>
<tbody>
#foreach($roles as $role)
<tr>
<td>{{ $role->name }}</td>
<td>
{!! Form::open(['route' => ['roles.destroy', $role->id], 'method' => 'delete']) !!}
<div class='btn-group'>
</i>
</i>
{!! Form::button('<i class="glyphicon glyphicon-trash"></i>', ['type' => 'submit', 'class' => 'btn btn-danger btn-xs', 'onclick' => "return confirm('Are you sure?')"]) !!}
</div>
{!! Form::close() !!}
</td>
</tr>
#endforeach
</tbody>
</table>
I never used Form class, but I think you could try just passing in $role.
Related
#extends('layouts.app')
#section('content')
<div class="row">
<div class="col-lg-12 margin-tb">
<div class="pull-left">
<h2>Users Management</h2>
</div>
<div class="pull-right">
<a class="btn btn-success" href="{{ route('users.create') }}"> Create New User</a>
</div>
</div>
</div>
#if ($message = Session::get('success'))
<div class="alert alert-success">
<p>{{ $message }}</p>
</div>
#endif
<table class="table table-bordered">
<tr>
<th>No</th>
<th>Name</th>
<th>Email</th>
<th>Roles</th>
<th width="280px">Action</th>
</tr>
#foreach ($data as $key => $user)
<tr>
<td>{{ ++$i }}</td>
<td>{{ $user->name }}</td>
<td>{{ $user->email }}</td>
<td>
#if(!empty($user->getRoleNames()))
#foreach($user->getRoleNames() as $v)
<label class="badge badge-success">{{ $v }}</label>
#endforeach
#endif
</td>
<td>
<a class="btn btn-info" href="{{ route('users.show',$user->id) }}">Show</a>
<a class="btn btn-primary" href="{{ route('users.edit',$user->id) }}">Edit</a>
{!! Form::open(['method' => 'DELETE','route' => ['users.destroy', $user->id],'style'=>'display:inline']) !!}
{!! Form::submit('Delete', ['class' => 'btn btn-danger']) !!}
{!! Form::close() !!}
</td>
</tr>
#endforeach
</table>
{!! $data->render() !!}
<p class="text-center text-primary"><small>Tutorial by ItSolutionStuff.com</small></p>
#endsection
Im agree with Gary, if you are using Spatie add the next code to User.php
use Spatie\Permission\Traits\HasRoles;
class User extends Authenticatable
{
use HasApiTokens, HasFactory, Notifiable, HasRoles;
Please add this method into User.php model file
public function getRoleNames()
{
return $this->belongsToMany(Role::class);
}
If this method not work then share you table structure and user model file code.
In the controller that call this view, you should to do:
$data = Model::all(); // ---> this solved that for me
return view('model.view',compact('data'));
cart.blade.php
#extends('master')
#section('content')
<div class="container">
#if(Cart::isEmpty())
<b>The card is empty</b> Shopping now
#else
<table class="table table-condensed table-bordered">
<thead>
<tr>
<th>item id</th>
....
</tr>
</thead>
<tbody>
{!! Form::open(["url"=>"/pay"]) !!}
<?php $i = 0; $totalCart_price = 0; ?>
#foreach($cart_total_items as $item)
<tr>
<td>{{ $item['id'] }}</td>
....
<td>
{!! Form::open(["url"=>"/my-cart/".$item['id'], "method"=>"DELETE", "style"=>"display: inline"]) !!}
<button type="submit" class="btn btn-danger" aria-label="Left Align">
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
</button>
{!! Form::close() !!}
</td>
</tr>
<?php $i++; $totalCart_price += Cart::get($item['id'])->getPriceSum(); ?>
#endforeach
</tbody>
</table>
<b>Total price: ${{ $totalCart_price }} {{ Form::hidden("total_price", $totalCart_price) }}</b>
<br><br>
{!! Form::submit('check out (paypal)', ["class"=>"btn btn-primary"]) !!}
{!! Form::close() !!}
Clear cart
#endif
</div>
#stop
Issue: I can delete any item, but during click check out nothing happens, but when I remove clear item form, check out run successfully.
I want to run two operations, How Can I solve it?
Thanks
You can have several forms in a page but they should not be nested.
As given in html5 working draft:
4.10.3 The form element
Content model:
Flow content, but with no form element descendants.
As far as I know form is just the html tags which can be used to send a group(array) of data at once to the server.
In your case your best bet would be to use the ajax query.(though it would make our page javascript dependent)
Or, as I observed you can just seperate the two form like below:
#extends('master')
#section('content')
<div class="container">
#if(Cart::isEmpty())
<b>The card is empty</b> Shopping now
#else
<table class="table table-condensed table-bordered">
<thead>
<tr>
<th>item id</th>
....
</tr>
</thead>
<tbody>
<<!-- Remove the Form tag from here and insert it below -->>
<?php $i = 0; $totalCart_price = 0; ?>
#foreach($cart_total_items as $item)
<tr>
<td>{{ $item['id'] }}</td>
....
<td>
{!! Form::open(["url"=>"/my-cart/".$item['id'], "method"=>"DELETE", "style"=>"display: inline"]) !!}
<button type="submit" class="btn btn-danger" aria-label="Left Align">
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
</button>
{!! Form::close() !!}
</td>
</tr>
<?php $i++; $totalCart_price += Cart::get($item['id'])->getPriceSum(); ?>
#endforeach
</tbody>
</table>
<<!-- Remove the Form tag from above and insert it below -->>
{!! Form::open(["url"=>"/pay"]) !!}
<b>Total price: ${{ $totalCart_price }} {{ Form::hidden("total_price", $totalCart_price) }}</b>
<br><br>
{!! Form::submit('check out (paypal)', ["class"=>"btn btn-primary"]) !!}
{!! Form::close() !!}
Clear cart
#endif
</div>
#stop
I am creating a simple crud application with file upload. But i have problems in displaying the thumbnail in view(index.blade.php). All images in database are displayed in each book instead of displaying one image in one book. Here is my controller.
public function index()
{
$books=UploadedFile::all();
$files=Upload::all();
return view('books.index',compact('books','files'));
}
and my index.blade.php
<table class="table table-striped table-bordered table-hover">
<thead>
<tr class="bg-info">
<th>Id</th>
<th>ISBN</th>
<th>Title</th>
<th>Author</th>
<th>Publisher</th>
<th>Thumbs</th>
<th colspan="3">Actions</th>
</tr>
</thead>
<tbody>
#foreach ($books as $book )
<tr>
<td>{{ $book->id }}</td>
<td>{{ $book->isbn }}</td>
<td>{{ $book->title }}</td>
<td>{{ $book->author }}</td>
<td>{{ $book->publisher }}</td>
<td>
#foreach ($files as $file )
<img src="{{asset('uploads/'.$file->filename)}}" height="40" width="50">
#endforeach
</td>
<td>Details</td>
<td>Update</td>
<td>
{!! Form::open(['method' => 'DELETE', 'route'=>['books.destroy', $book->id]]) !!}
{!! Form::submit('Delete', ['class' => 'btn btn-danger']) !!}
{!! Form::close() !!}
</td>
</tr>
#endforeach
</tbody>
</table>
I separated the table for the filename from the rest of the fields. and here is the result--
This is the code where I need to set the value for the label :
{!! Form::label('unit',$value=$fileN) !!}
When I coded that it will display the following error.
ErrorException in UploadController.php line 51:
Undefined index: unit
I changed that to {{ Form::label('unit', $fileN) }}. But above same error will display. Below is the output.
<label for="unit">rainforest.pdf</label>
Controller method look likes below.
public function edit1()
{
$grade = $_POST['grade'];
$subject = $_POST['subject'];
$id = $_POST['id'];
$title = $_POST['title'];
$unit = $_POST['unit'];
$uplds = Upldtbl::findOrFail($id);
DB::table('upldtbls')
->where('id', $id)
->update(['title' => $title, 'subject' => $subject,'url' => $unit, 'grade' => $grade]);
return redirect('/hgh');
}
{!! Form::open(array('url'=>'hgh1','method'=>'POST', 'files'=>true, 'class'=>'upldform')) !!}
<table>
<div class="control-group">
<div class="controls">
<tr>
<td> <b>{!! Form::label('Grade', 'Grade') !!}</b></td>
<td> {!! Form::select('grade', array('Grade' => 'Grade','2' => '2', '3' => '3','4' => '4'), $value=$grade) !!}</td>
</tr>
#if(Session::has('errorUpldGrade'))
<tr>
<td><ul class="alert alert-danger" style="width: 250px;height: 40px">{!! Session::get('errorUpldGrade') !!}</ul></td>
</tr>
#endif
<tr>
<td><b>{!! Form::label('Subject', 'Subject') !!}</b></td>
<td>{!! Form::select('subject', array('Subject' => 'Subject','English' => 'English', 'Mathematics' => 'Mathematics','Environmental Studies' => 'Environmental Studies'), $value=$sub) !!}</td>
</tr>
#if(Session::has('errorUpldSubj'))
<tr>
<td><ul class="alert alert-danger" style="width: 250px;height: 40px"><p class="errors">{!! Session::get('errorUpldSubj') !!}</p></ul></td>
</tr>
#endif
<tr>
<td> <b>{!! Form::label('Title', 'Title') !!}</b></td>
<td> {!! Form::text('title',$value=$title) !!}</td>
</tr>
#if(Session::has('errorUpldTitle'))
<tr>
<td><ul class="alert alert-danger" style="width: 250px;height: 40px"><p class="errors">{!! Session::get('errorUpldTitle') !!}</p></ul></td>
</tr>
#endif
<tr>
<td>{!! Form::file('image') !!}{{ Form::label('unit', $fileN) }}</td>
<td><p class="errors">{!!$errors->first('image')!!}</p></td>
</tr>
#if(Session::has('errorUpldFile'))
<tr>
<td><ul class="alert alert-danger" style="width: 250px;height: 40px"><p class="errors">{!! Session::get('errorUpldFile') !!}</p></ul></td>
</tr>
#endif
<td>{!! Form::hidden('id',$id ) !!}</td><br>
</div>
</div>
<tr>
<td> {!! Form::submit('Update', array('class'=>'send-btn')) !!}</td>
</tr>
</table>
{!! Form::close() !!}
Can anybody help me that out?
You have a wrong declaration of label, instead of :
{!! Form::label('unit',$value=$fileN) !!}
It should be :
{{ Form::label('unit', $fileN) }}
And you're getting the error Undefined index: unit because you don't have any field with name unit and you're trying to capture it in :
$unit = $_POST['unit'];
You could use hidden field to send value of unit like :
{!! Form::hidden('unit',$fileN) !!}
Hope this helps.
index.blade.php
I am using img src="{{ URL::asset($task->image) }}" to display image but its not working...please suggest me on how to achieve it..
any help???
#extends ('welcome')
#section ('content')
<h1 class="headng"> Form List </h1>
<table class="table table-hover ">
<tr>
<th><h4>Title</h4></th>
<th><h4>Description</h4></th>
<th><h4>Image</h4></th>
<th><h4>Printable</h4></th>
<th><h4>Actions</h4></th>
</tr>
#foreach($tasks as $task)
<tr>
<td>{{ $task->title }}</td>
<td>{{ $task->description }}</td>
<td><img src="{{ URL::asset($task->image) }}" /></td>
<td>{{ $task->printable }}</td>
<td>
<a href = '{{ action('TasksController#edit',[$task->id]) }}'>Edit</a> |
{!! Form::open([
'method' => 'DELETE',
'route' => ['tasks.destroy', $task->id]
]) !!}
{!! Form::submit('Delete', ['class' => 'btn btn-danger']) !!}
{!! Form::close() !!}
</td>
</tr>
#endforeach
</table>
#stop