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
Related
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.
I am working on laravel project for the first time and i am stuck here with display table.
I just copy and paste one code from google.
#extends('layout/template')
#section('content')
<h1>Peru BookStore</h1>
Create Book
<hr>
<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><img src="{{asset('img/'.$book->image.'.jpg')}}" height="35" width="30"></td>
<td>Read</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>
#endsection
I am using this code and problem is my blade commands are visible in
webpage. I hear that there is no need to use php tags if i am using
blade.php. whats wrong with my code please help me with the same.
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.