In laravel, I have resource controller :
Route::resource('/student','StudentController');
here is my view listing code :
<tr>
<td>{{ $key + $models->firstItem() }}</td>
<td>{{ $model->name }}</td>
<td>{{ $model->email }}</td>
<td>{{ $model->roll_no }}</td>
<td>{{ $model->StudentDetail->phone }}</td>
<td>{{ $model->StudentDetail->course }}</td>
<td>{{ $model->StudentDetail->city }}</td>
<td>{{ $model->StudentDetail->state->state_name }}</td>
<td>
Edit |
Link
</td>
</tr>
conytroller function i have :
public function destroy($id)
{
echo "ok";
}
My problem is that when I click on anchor button(delete ) it not
found the resource route for the delete what I am doing wrong here can
anyone please help me elated this.
when I click on the delete anchor it calls the show function of resource but I want the destroy function to call on click.
destroy function use DELETE method
in your blade view
#foreach($students as $model)
<tr>
<td>{{ $key + $models->firstItem() }}</td>
<td>{{ $model->name }}</td>
<td>{{ $model->email }}</td>
<td>{{ $model->roll_no }}</td>
<td>{{ $model->StudentDetail->phone }}</td>
<td>{{ $model->StudentDetail->course }}</td>
<td>{{ $model->StudentDetail->city }}</td>
<td>{{ $model->StudentDetail->state->state_name }}</td>
<td>
Edit |
DELETE
<form id="delete_form" style="display:none" action="{{ route('student.destroy',$model->id)}}" method="POST" >
{{ csrf_field() }}
<input type="hidden" name="_method" value="delete" />
</form>
</td>
</tr>
#endforeach
Related
hello can you help me? so i am paginating on server side, but when i try to display on client side i get error like this...
i can say I can't use firstItem(), Thanks for your response, I hope this gets the answer..
In Controller
$response = Http::withHeaders([
'X-Authorization' => 'NkKeAs7Og8O6WcNste9OsAjkui2pSZnjZr6WOcDf1EjU1UDPuz88CATNqFI2rkSN'
])->get('http://www.Api.net/api/get-produk', [
'type_product' => $filter,
'limit' => $request->length,
'offset' => $request->start,
]);
$data = json_decode($response);
In Rest API
$produk = Daftarproduk::select('cat_number', 'brand', 'nama_produk', 'host', 'reactivity', 'clone_type', 'application', 'pack_size', 'type_product', 'pack_category', 'price')
->where('type_product', $request->get('type_product'))
->offset($request->offset)
->limit($request->limit)
->paginate();
In View
<tbody>
#foreach ($produk->data as $item)
<tr>
<td>{{ $loop->iteration }}</td>
<td>{{ $item->cat_number }}</td>
<td>{{ $item->brand }}</td>
<td>{{ $item->nama_produk }}</td>
<td>{{ $item->host }}</td>
<td>{{ $item->reactivity }}</td>
<td>{{ $item->clone_type }}</td>
<td>{{ $item->application }}</td>
<td>{{ $item->pack_size }}</td>
<td>{{ $item->type_product }}</td>
<td>{{ $item->price }}</td>
</tr>
#endforeach
</tbody>
</table>
<div class="d-flex justify-content-start">
Showing
{{ $produk->firstItem() }}
to
{{ $produk->lastItem() }}
of
{{ $produk->total() }}
Entries
</div>
<div class="d-flex justify-content-end">
{{ $produk->links() }}
</div>
I tried to display data inside a table for admin.
Here is my admin.blade.php:
<form method="post" action="post_namaadmin">
<input type="text" name="txtnamaadmin" id="txtnamadmin" value="1">
<input type="submit" name="btnnamadmin" id="btnamaadmin">
</form>
<div class="card-body">
<table border="1">
#foreach($datalama as $rows)
<tr>
<td>ID : </td>
<td>{{ $rows->userid }}</td>
<td>Nama : </td>
<td>{{ $rows->nama }}</td>
</tr>
<tr>
<td>Section</td>
<td>IM</td>
<td>CO</td>
<td>SH</td>
<td>PL</td>
<td>RI</td>
<td>ME</td>
<td>TB</td>
<td>CF</td>
</tr>
<tr>
<!-- //1 -->
<td>{{ $rows->a1 }}</td>
<td>{{ $rows->b1 }}</td>
<td>{{ $rows->c1 }}</td>
<td>{{ $rows->d1 }}</td>
<td>{{ $rows->f1 }}</td>
<td>{{ $rows->g1 }}</td>
<td>{{ $rows->h1 }}</td>
<!-- //1 -->
<td>{{ $rows->a2 }}</td>
<td>{{ $rows->b2 }}</td>
<td>{{ $rows->c2 }}</td>
<td>{{ $rows->d2 }}</td>
<td>{{ $rows->f2 }}</td>
<td>{{ $rows->g2 }}</td>
<td>{{ $rows->h2 }}</td>
<!-- //3 -->
<td>{{ $rows->a3 }}</td>
<td>{{ $rows->b3 }}</td>
<td>{{ $rows->c3 }}</td>
<td>{{ $rows->d3 }}</td>
<td>{{ $rows->f3 }}</td>
<td>{{ $rows->g3 }}</td>
<td>{{ $rows->h3 }}</td>
<!-- //4 -->
<td>{{ $rows->a4 }}</td>
<td>{{ $rows->b4 }}</td>
<td>{{ $rows->c4 }}</td>
<td>{{ $rows->d4 }}</td>
<td>{{ $rows->f4 }}</td>
<td>{{ $rows->g4 }}</td>
<td>{{ $rows->h4 }}</td>
<!-- //5 -->
<td>{{ $rows->a5 }}</td>
<td>{{ $rows->b5 }}</td>
<td>{{ $rows->c5 }}</td>
<td>{{ $rows->d5 }}</td>
<td>{{ $rows->f5 }}</td>
<td>{{ $rows->g5 }}</td>
<td>{{ $rows->h5 }}</td>
<!-- //6 -->
<td>{{ $rows->a6 }}</td>
<td>{{ $rows->b6 }}</td>
<td>{{ $rows->c6 }}</td>
<td>{{ $rows->d6 }}</td>
<td>{{ $rows->f6 }}</td>
<td>{{ $rows->g6 }}</td>
<td>{{ $rows->h6 }}</td>
<!-- //7 -->
<td>{{ $rows->a7 }}</td>
<td>{{ $rows->b7 }}</td>
<td>{{ $rows->c7 }}</td>
<td>{{ $rows->d7 }}</td>
<td>{{ $rows->f7 }}</td>
<td>{{ $rows->g7 }}</td>
<td>{{ $rows->h7 }}</td>
</tr>
#endforeach
</table>
</div>
The code is not yet completed, but it should give a rough picture of the table.
Here is my route in web.php:
Route::post('/post_namaadmin', 'DataController#admin' ) ->name ('postnamaadmin');
Function in DataController.php :
public function admin(Request $request){
$mk = new data();
$param['datalama'] = $mk->ambilData($request->txtnamaadmin);
return view('admin',$param);
}
Function in data class :
public function ambilData($nama){
$query = data::orderby('userid')->where('nama','=' ,'$nama')->first();
return $query;
}
Here is the error:
> ErrorException {#230 ▼ #message: "Invalid argument supplied for
> foreach()" #code: 0 #file:
> "C:\xampp\htdocs\kuesioner1\storage\framework\views\5c1b0932d9bc5a402e110419f0ce7e166c7a2109.php"
> #line: 22 #severity: E_WARNING } 1
I'm new in Laravel. For why I use 5.8, my superior demand me so. All help and suggestion is highly appreciated.
When you try to dd($param['datalama']), you will get null, because your query found nothing, using ->where('nama','=' ,'$nama').
You need to change data class ambilData method
public function ambilData($nama){
return data::orderby('userid')
->where('nama', $nama)
->get();
}
I think you should put $param['datalama'] in the foreach instead
and change the view function to view('admin',compact('param'))
and in the form tag you need to change the action to
<form action="{{route('postnamaadmin')}}">
I've got the following code which shows my clubs fixtures/results list for upcoming games:
<div class="row">
<div class="col-md-10 col-md-offset-1">
<span id="hide" class="first">1st XV Fixtures/Results</span><span id="show">2nd XV Fixtures/Results</span>
<table class="table table-bordered table-hover">
<tr>
<th>Date</th>
<th>Venue</th>
<th>Opposition</th>
<th>Kick Off</th>
<th>Type</th>
<th>Score</th>
<th>Result</th>
</tr>
#foreach ($fixtures as $fix)
#if($fix['team'] === 1)
<tr class="clickableRow success league_table" href="{{ action('DynamicPages#match',[$fix['id']]) }}">
<td>{{ date("d/m/Y",strtotime($fix['mdate'])) }}</td>
<td>{{ $fix['venue'] }}</td>
<td>{{ $fix['opposition'] }}</td>
<td>{{ date("H:i",strtotime($fix['mdate'])) }}</td>
<td>{{ $fix['type'] }}</td>
#foreach($results as $result)
#if($result['match_id']=== $fix['id'])
#if(!empty($result['score']))
<td>{{ $result['score'] }}</td>
<td>{{ $result['result'] }}</td>
#else
<td> </td>
<td> </td>
#endif
#endif
#endforeach
</tr>
#else
<tr class="clickableRow danger merit-table" style="display:none;" href="{{ action('DynamicPages#match',[$fix['id']]) }}">
<td>{{ date("d/m/Y",strtotime($fix['mdate'])) }}</td>
<td>{{ $fix['venue'] }}</td>
<td>{{ $fix['opposition'] }}</td>
<td>{{ date("H:i",strtotime($fix['mdate'])) }}</td>
<td>{{ $fix['type'] }}</td>
#foreach($results as $result)
#if($result['match_id']=== $fix['id'])
#if(isset($result['score']))
<td>{{ $result['score'] }}</td>
<td>{{ $result['result'] }}</td>
#else
<td> </td>
<td> </td>
#endif
#endif
#endforeach
</tr>
#endif
#endforeach
</table>
</div>
</div>
I want it to show the score from the DB, but if thats blank, then just to show a blank table with a background colour. However, it's simple showing nothing so when I look at it, it shows a white space.
Can anyone help?
I'm trying to understand Laravel, but i'm stuck
When I try this code:
#foreach($nerds as $key =>$value)
<tr>
<td>{{ $value->id }}</td>
<td>{{ $value->name }}</td>
<td>{{ $value->email }}</td>
<td>{{ $value->nerd_level }}</td>
</tr>
#endforeach
it displays litterally "{{ $value->id }}" etc in a list on the site.
Anyone?
I have created somewhat of a search feature, where a user can choose a type, pool, date and time. I can't seem to make the paginator to work, as when I click on page 2 the results disappear.
I have tried to append the $query->links() function, but none of my tries have yet succeeded.
The URL looks like this: http://localhost:8080/nih/public/bassengweb/data?time_maling=1&pool_id=1&fraDato=14%2F04%2F2014&tilDato=22%2F04%2F2014&fraTid=00%3A01&tilTid=23%3A59
The code for the view file:
#extends('default')
#section('content')
<h1>ADMIN SØK</h1>
{{ Form::open(array('url' => 'bassengweb/data', 'method' => 'GET')) }}
<table>
<tr>
<td>{{ Form::label('time_maling', 'Timemåling') }}</td>
<td>{{ Form::checkbox('time_maling', 1) }}</td>
<td>{{ Form::label('3_time_maling', '3. Timemåling') }}</td>
<td>{{ Form::checkbox('3_time_maling', 1) }}</td>
<td>{{ Form::label('oppgaver', 'Oppgaver') }}</td>
<td>{{ Form::checkbox('oppgaver', 1) }}</td>
<td>{{ Form::label('pool_id', 'Basseng') }}</td>
<td>{{ Form::select('pool_id', $pools, Input::old('pool_id')) }}</td>
</tr>
<tr>
<td>{{ Form::label('dagsoppg', 'Dagvakt') }}</td>
<td>{{ Form::checkbox('dagsoppg', 1) }}</td>
<td>{{ Form::label('kveldsoppg', 'Kveldsvakt') }}</td>
<td>{{ Form::checkbox('kveldsoppg', 1) }}</td>
<td>{{ Form::label('helgoppg', 'Helgevakt') }}</td>
<td>{{ Form::checkbox('helgsoppg', 1) }}</td>
</tr>
<tr>
<td>{{ Form::label('kontcm', 'Kontroll CM') }}</td>
<td>{{ Form::checkbox('kontcm', 1) }}</td>
<td>{{ Form::label('arduino', 'Arduino') }}</td>
<td>{{ Form::checkbox('arduino', 1) }}</td>
<td><hr/></td>
</tr>
<tr>
<td>{{ Form::label('fraDato', 'Fra dato: ') }}</td>
<td>{{ Form::text('fraDato', Input::old('fraDato'), array('placeholder' => $date)) }}</td>
<td>{{ Form::label('tilDato', 'Til dato: ') }}</td>
<td>{{ Form::text('tilDato', Input::old('tilDato'), array('placeholder' => $date)) }}</td>
</tr>
<tr>
<td>{{ Form::label('fraTid', 'Fra klokka: ') }}</td>
<td>{{ Form::text('fraTid', Input::old('fraTid'), array('placeholder' => '10:55:31')) }}</td>
<td>{{ Form::label('tilTid', 'Til klokka: ') }}</td>
<td>{{ Form::text('tilTid', Input::old('tilTid'), array('placeholder' => '10:55:31')) }}</td>
<td>{{ Form::submit('Søk') }}<td>
</tr>
</table>
{{ Form::close() }}
#if(isset($data))
<table class='table table-hover'>
<tr>
<td>ID</td>
<td>Tittel</td>
<td>Verdi</td>
<td>Ansatt ID</td>
<td>Dato</td>
<td>Tid</td>
#if($type === 'measurement')
<td>Basseng</td>
</tr>
#foreach($data as $dataItem)
<tr>
<td>{{ $dataItem->id }}</td>
<td>{{ $dataItem->measurements[0]->title }}</td>
<td>{{ $dataItem->value }}</td>
<td>{{ $dataItem->emps->user_name }}</td>
<td>{{ date('d/m/Y', strtotime($dataItem->date)) }}</td>
<td>{{ $dataItem->time }}</td>
#foreach($dataItem->measurements as $measurement)
<td>{{ $pools[$measurement->pivot->pool_id] }}</td>
#endforeach
<td>{{ HTML::linkRoute('edit_data', 'Rediger', $dataItem->id) }}</td>
<td>{{ HTML::linkRoute('delete_confirm', 'Slett', $dataItem->id) }}
</td>
</tr>
#endforeach
</table>
{{ $data->appends(array($type => 1, Input::except('page')))->links() }}
#elseif($type === 'task')
</tr>
#foreach($data as $dataItem)
<tr>
<td>{{ $dataItem->id }}</td>
<td>{{ $dataItem->tasks[0]->title }}</td>
<td>{{ $dataItem->value }}</td>
<td>{{ $dataItem->emps->user_name }}</td>
<td>{{ date('d/m/Y', strtotime($dataItem->date)) }}</td>
<td>{{ $dataItem->time }}</td>
<td>{{ HTML::linkRoute('edit_data', 'Rediger', $dataItem->id) }}</td>
<td>{{ HTML::linkRoute('delete_confirm', 'Slett', $dataItem->id) }}</td>
</tr>
#endforeach
#endif
#endif
#stop
Thanks.
You nested array withing appends method:
$data->appends(array($type => 1, Input::except('page')))->links()
// returns
array(
$type => 1,
array(
... // Input/Request params are ignored as a nested array
)
)
Change it to:
$data->appends(array_merge(array($type => 1), Input::except('page')))->links()