Laravel: Input old for radio button - php

I want to insert Input::old with my radio buttons
<td>{{ Form::radio('student['.$user->student_id.'][status]', 'present', (Input::old('student') == 'present')) }}</td>
<td>{{ Form::radio('student['.$user->student_id.'][status]', 'late', (Input::old('student') == 'late')) }}</td>
<td>{{ Form::radio('student['.$user->student_id.'][status]', 'absent', (Input::old('student') == 'absent')) }}</td>
<td>{{ Form::radio('student['.$user->student_id.'][status]', 'others', (Input::old('student') == 'others')) }}</td>
I tried this and it doesn't work :( Please help

Try like this
{{ Form::radio('student', 'present', (Input::old('student') == 'present'), array('id'=>'present', 'class'=>'radio')) }}

Related

Call to a member function count() on null

When I'm going to add data an error appears "Call to a member function count() on null"
View
#foreach ($data as $row)
<tr>
<td>{{ $row->customer}}</td>
<td>{{ $row->vessel}}</td>
<td>{{ $row->scopejob}}</td>
<td>{{ $row->pergantian_sparepart}}</td>
<td>{{ $row->teknisi}}</td>
<td>{{ $row->tahun}}</td>
<td>{{ $row->keterangan}}</td>
<td>{{ $row->images->count()}}</td>
<td>{{ $row->files->count()}}</td>
<td>
FOTO
FILE
EDIT
<a href="#" class="btn btn-danger delete m-1" data-id="{{ $row->id}}" data-customer="{{ $row->customer}}" >DELETE</a>
</td>
</tr>
#endforeach
Controller rekap:
public function insert_rekap(Request $request) {
// dd($request->all());
$this -> validate($request,[
'customer'=>'required',
'vessel'=>'required',
'scopejob'=>'required',
'pergantian_sparepart'=>'required',
'teknisi'=>'required',
'tahun'=>'required',
'keterangan'=>'required'
]);
$data = rekap::create($request->all());
if($request->hasFile("images")){
$images=$request->file("images");
foreach($images as $image){
$imageName=time().'_'.$image->getClientOriginalName();
$request['rekap_id']=$data->id;
$request['image']=$imageName;
$image->move(public_path("/images_rekap"),$imageName);
Image_rekap::create($request->all());
}if($request->hasFile("files")){
$files=$request->file("files");
foreach($files as $file){
$fileName=time().'_'.$file->getClientOriginalName();
$request['rekap_file_id']=$data->id;
$request['file']=$fileName;
$file->move(\public_path("/rekap_file"),$fileName);
file_rekap::create($request->all());
}
}
}
return redirect()->route('rekap')->with('success','Data Berhasil Ditambahkan');
}
but the data is successfully entered into the database, and what steps should I take to correct the error
error tells you that images or files or both variables are null, looks like you don't use eager loading
quick and dirty way is to use optional helper
<td>{{ optional($row->images)->count()}}</td>
<td>{{ optional($row->files)->count()}}</td>
if you need only count then better approach is to use eloquent counting related models
// controller
$data = rekap::withCount(['images', 'files'])
// other selecting rules
//->where ...
->get();
return view('view_name', ['data'=>$data]);
now in every $row of $data you have fields images_count and files_count
<td>{{ $row->images_count }}</td>
<td>{{ $row->files_count }}</td>
also you can rename count variables like rekap::withCount(['images as imagesCount', 'files as filesCount'])
<td>{{ $row->imagesCount }}</td>
<td>{{ $row->filesCount }}</td>
Try
<td>{{ $row->images ? $row->images->count() : '' }}</td>

print days of a special month ? laravel

I need to print only the records for the month of May
I get them with the variable
<td>{{ ($registro->created_at->format('d-m-Y')) }}</td>
I need to see only May results, how do I do it?
You can use if condition
#if($user->created_at->format('M')=="May")
<td>{{ ($registro->created_at->format('d-m-Y')) }}</td>
#endif
or
#if($user->created_at->format('m')=="05")
<td>{{ ($registro->created_at->format('d-m-Y')) }}</td>
#endif
Simply check May month in created_at date
#if($user->created_at->format('m')=="05")
<td>{{ ($registro->created_at->format('d-m-Y')) }}</td>
#endif

Laravel modify cells with expired date

Sorry I didn´t know how to ask this question, but I want if a file reach his expiration date in each cell of expired date column just put "expired" otherwise just put his expiration date.
In my controller I create an variable called $actualDate= Carbon::now(); and I send it to my view.
In my view I have this on table:
#foreach ($Files as $File)
<tr>
<td><a href="/File/{{$File->id}}">{{
$File->Code}}</td>
<td>{{ $File->created_at }}</td>
<td>{{ $File->person}}</td>
<td>{{ $File->category_file}}</td>
<td>{{ $File->status}}</td>
<td>{{ $File->employed}}</td>
#if($File->expirationDate < $actualDate)
<td>{{$File->expirationDate}}</td>
#else
<td>Expired</td>
#endif
If I put < on comparision all the column will be "expired" and if I put > it will be no expired Files even if there are ¿what can I do to solve this? I hope you can help me.
Try it:
#foreach ($Files as $File)
<tr>
<td><a href="/File/{{$File->id}}">{{ $File->Code}}</td>
<td>{{ $File->created_at }}</td>
<td>{{ $File->person}}</td>
<td>{{ $File->category_file}}</td>
<td>{{ $File->status}}</td>
<td>{{ $File->employed}}</td>
#if(\Carbon\Carbon::parse($File->expirationDate)->lessThan(\Carbon\Carbon::now()))
<td>{{$File->expirationDate}}</td>
#else
<td>Expired</td>
#endif
#endforeach
Hope it helps.

Compare two different columns from two different tables and show other column's data from either table in laravel 5.2

Compare two different columns from two different tables with if statement and show other column's data from either table in laravel 5.2
controller like:
public function labDetails(){
$users = DB::table('users')->lists('lab_name');
$labdetails = Labdetails2::paginate(20);
return View('labdetails')
->with('users', $users)
->with('labdetails', $labdetails);
}
here i want to match users table's 'lab_name' column with labdetails2 table's 'lab_name' column and if they matched show only the related data from labdetails table.
N.B. I am working with an old database where there's no relationship among tables.
views like:
<form action="" method="">
<select name="state" onchange="getValue(this)">
<option value="">Select Lab</option>
#foreach ($users as $key => $user)
<option value="{{ $user }}">{{ $user }}</option>
#endforeach
</select>
<input type="submit" value="Submit">
#foreach ($labdetails as $labdetail)
<tbody>
<tr>
<td>{{ $labdetail->sl }}</td>
<td>{{ $labdetail->lab_name }}</td>
<td>{{ $labdetail->pc_name }}</td>
<td>{{ $labdetail->pc_ip }}</td>
<td>{{ $labdetail->mac1 }}</td>
<td>{{ $labdetail->assetno }}</td>
<td>{{ $labdetail->pc_type }}</td>
<td>{{ $labdetail->processor }}</td>
<td>{{ $labdetail->motherboard }}</td>
<td>{{ $labdetail->ram }}</td>
<td>{{ $labdetail->hdd }}</td>
<td>{{ $labdetail->location }}</td>
<td>{{ $labdetail->department }}</td>
<td>{{ $labdetail->entrydate }}</td>
<td>{{ $labdetail->comment }}</td>
</tr>
</tbody>
#endforeach
Please help me what should I do with the controller & views...
You can retrieve only the matches record this way
$users = DB::table('users')->lists('lab_name'); // this retrieves all lab_name as array.
Then, to retrieve only the matches labdetails
$labdetails = Labdetails2::whereIn('lab_name',$users)->paginate(20);
DB::table('users')
->join('labdetails2', 'users.lab_name', '=', 'labdetails2.lab_name')
->select('labdetails2.lab_name', 'labdetails2.pc_name')
->get()
in select(), white down the fields you required.
Here, labdetails2 and users are the table name.
this code finally worked for me:
public function showLabDetails(Request $request){
$q = $request -> request -> all();
$labdetails = Labdetails2::whereIn('lab_name', $q)->get();
return View('showlabdetails')
->with('labdetails', $labdetails);
}
thanks to everyone for helping me.

Case statements when updating a table based on clicked button?

I've got a table like below:
<tr>
<td>{{ item.wo_num_and_date }}</td>
<td>{{ item.comp_name_and_number }}</td>
<td>{{ item.finish_sizes }}</td>
<td>{{ item.material }}</td>
<td>{{ item.total_num_pieces }}</td>
<td>{{ item.workorder_num_one }}</td>
<td>{{ item.notes_one }}</td>
<td id='signoff_userone'><input type='button' id='signoff_user_one' data-rowid={{ item.id }} value='Signoff' /> {% if item.signoff_user_one is defined and item.signoff_date_one is defined %}{{ item.signoff_user_one.name|title }} {{ item.signoff_date_one }} {% endif %}</td>
<td>{{ item.workorder_num_two }}</td>
<td>{{ item.notes_two }}</td>
<td id='signoff_usertwo'><input type='button' id='signoff_user_two' data-rowid={{ item.id }} value='Signoff' /> {% if item.signoff_user_two is defined and item.signoff_date_two is defined %}{{ item.signoff_user_two.name|title }} {{ item.signoff_date_two }} {% endif %}</td>
<td>{{ item.workorder_num_three }}</td>
<td>{{ item.notes_three }}</td>
<td><input type='button' id='signoff_user_three' value='Signoff' /> {{ item.signoff_user_three.firstname }} {{ item.signoff_user_three.lastname }}</td>
</tr>
Fiddle: http://jsfiddle.net/qwUV4/1/
Here's my php code I call when a button is clicked, everything works well for the first "Sign Off" box but the other 2 don't work, obviously because of my Update statement below which is only set to update column "signoff_user_one".
<?php
require_once('../includes/config.php');
$user_id = getuserinfo($loggedin_id);
$row_id = (int)mysqli_escape_string($dbc3, $_POST['rowid']);
$sql = "UPDATE checklist_component_stock SET signoff_user_one = $loggedin_id, signoff_date_one = NOW() WHERE id = " . $row_id;
mysqli_query($dbc3, $sql);
$ret = array('rowid' => $row_id, 'user' => $user_id, 'date' => date('Y-m-d H:i:s')); //date('M d, Y')
echo json_encode($ret);
?>
My question is, would I need cases so the script checks whether its signoff_user_one, user_two, or user_three and executes the correct update statement? How would I do something like that? Is there another solution?
Are you using a loop? Because in such a case, it would probably not work very well.It should work well with the buttons and the specific ids which you have captured.You could use an isset function and use the name attribute for the button..

Categories