I'm trying to call the timeStamp but it doesn't appear in my table. Here is my code:
#foreach($cevents as $cevent)
<tr >
<td class="col-lg-2">
{{ $cevent->name_client }}
</a>
</td>
<td class="col-lg-2">
{{ $cevent->name_event }}
</td>
<td class="col-lg-4">
{{ $cevent->details }}
</td>
<td class="col-lg-3">
{{ $cevent->created_at }}
</td>
</tr>
#endforeach
Using dd() in a controller I can find it, so the value is present.
How can I fix this?
Related
Here is the page where I am getting the error. Can someone help me ? I do not understand why I am having this issue
#foreach($allData as $key => $item)
<tr>
<td> {{ $key+1}} </td>
<td>{{ $item['category']['name'] }}</td>
<td> #{{ $item['invoice']['invoice_no'] }} </td>
<td> {{ date('d-m-Y',strtotime($item['invoice']['date'])) }} </td>
<td> {{ $item->due_amount }} </td>
<td>
<i class="fas fa-edit"></i>
<i class="fa fa-eye"></i>
</td>
</tr>
#endforeach
I am trying to print the customer invoice with the category of the product he bought, the name of the product, the invoice number and the date.
I have a component table
<x-table :rows="$rowsArray"></x-table>
I pass array of arrays where each inner array represents <tr> row to be printed.
$rowsArray = [
['name'=>'Marko', 'age'=>21],
['name'=>'John', 'age'=>33]
]
Inside a component table.blade.php:
I print each values as simple text
<table>
#foreach($rowsArray as $tr)
<tr>
#foreach($tr as $td_key => $td_value)
<td>
{{ $td_value }}
</td>
#endforeach
</tr>
#endforeach
</table>
As it is just printing string text, for situations I want different layout to be printed inside <td> I am passing layout through slot $customSlot.
Calling component with custom layout through slot
Hardcoded example ->
<x-table :rows="$rowsArray">
<x-slot name="customSlot">
<div class="flex">
<span>
Marko
</span>
<span>
21 age
</span>
</div>
</x-slot>
</x-table>
So updating code in table.blade.php
I am checking if slot is passed, if not print string text.
<table>
#foreach($rowsArray as $tr)
<tr>
#foreach($tr as $td_key => $td_value)
<td>
#if(isset($customSlot))
{{ $customSlot }}
#else
{{ $td_value }}
#endif
</td>
#endforeach
</tr>
#endforeach
</table>
PROBLEM:
I want to acces $tr data from current foreach iteration in slot scope, and not printing hardcoded values.
Here $tr['name'] and $tr['age'] are undefined, and I want it to be accessible from current iteration:
<x-slot name="customSlot">
<div class="flex">
<span>
{{ $tr['name'] }}
</span>
<span>
{{ $tr['age'] }} age
</span>
</div>
</x-slot>
Throws
$tr is undefined
Expected output from passed array:
<table>
<tr>
<td>
<div class="flex">
<span>Marko</span>
<span>21 age</span>
</div>
</td>
<td>
<div class="flex">
<span>John</span>
<span>33 age</span>
</div>
</td>
</tr>
</table>
Thank you for all the help in the past.
On my app, when i try to view a certain blade, it returns the error
"Trying to get property of non-object".
It has pointed me to the blade and the section of code where the error comes from:
#extends('layouts.app')
#section('content')
#component('dashboard.frame')
<div class="panel panel-default">
<div class="panel-heading">
Create
Activation Pins - {{ $item->name }}
</div>
{{--<div class="panel-body">--}}
{{--#if($pin_item && !$pin_item->pivot->is_paid )--}}
{{--<form action="/activation-pins/{{ $pin_item->id }}" method="post">--}}
{{--<input type="hidden" name="_method" value="PUT">--}}
{{--<input type="hidden" name="vendor_id" value="{{ $item->vendor->id }}">--}}
{{--{!! csrf_field() !!}--}}
{{--<button type="submit" class="btn btn-success">Mark As Paid</button>--}}
{{--</form>--}}
{{--#endif--}}
{{--</div>--}}
<table class="table">
<thead>
<tr>
<th>S/N</th>
<th>Name</th>
<th>Is Active</th>
<th>User</th>
</tr>
</thead>
<tbody>
#forelse($item->activation_pins as $itm)
<tr>
<td>{{ $loop->index + 1 }}</td>
<td>{{ $itm->pin }}</td>
<td>
<span class="label label-{{ $itm->is_active ? ( $itm->is_valid ? 'info' : 'danger' ) : 'warning' }}">
{{ $itm->is_active ? ( $itm->is_valid ? 'active' : 'expired' ) : 'inactive' }}
</span>
</td>
<td>
{{ $itm->user_id ? $itm->user->email : '-' }}
</td>
</tr>
#empty
<tr>
<td colspan="6">
<p class="text-center">No Activation Pins</p>
</td>
</tr>
#endforelse
</tbody>
</table>
</div>
#endcomponent
#endsection
With emphasis on:
<td>
{{ $itm->user_id ? $itm->user->email : '-' }}
</td>
Could I be missing something? Thanks.
This is what it displays now:
I would like to display data based on the chosen values from select box and search box. but select box ( maybe search box has same issue too) get reset whenever I click the page 2,3,4....
I believe I missed something with pagination code in the view / controller.
Please let me know the way to solve this issue.
Controller
class MemberListTestController extends Controller
{
public function search(Request $request)
{
$request->flash();
$memberName = $request->input('memberName');
$chosenCenter = $request->input('chosenCenter');
$memberLists= DB::table('tbMbrMember as Member')
->select(['Org.orgNm',
'Member.firstNm',
'Member.lastNm',
'Member.regDate',
'MshipCd.mshipNm',
'Att.dt',
'Member.phoneCell',
'Member.email',
'Group.groupNm',
DB::raw('MAX(Att.dt) AttDt, GREATEST(MAX(Reg.endDt),MAX(Reg.expDt)) rExpDt')])
->join('tbMbrCenter as Center', 'Member.mbrCd', '=', 'Center.mbrCd')
->join('tbCmOrg as Org', 'Center.orgCd', '=', 'Org.orgCd')
->leftjoin('tbMbrGroup as Group','Center.orgCd','=','Group.orgCd')
->leftjoin('tbMbrMshipReg as Reg', 'Member.mbrCd', '=', 'Reg.mbrCd')
->leftjoin('tbCmMshipCd as MshipCd', 'MshipCd.mshipCd', '=', 'Reg.mshipCd')
->leftjoin('tbMbrAtt as Att', 'Att.mbrCd', '=', 'Member.mbrCd')
->where('Center.orgCd', $chosenCenter)
->groupby('Member.mbrCd')
->paginate(25);
$centerLists = DB::table('tbMbrCenter as Center')
->select('Org.orgNm','Center.orgCd')
->join('tbCmOrg as Org', 'Center.orgCd', '=', 'Org.orgCd')
->where('Center.isShow','1')
->where('Org.companyCd','c1')
->where('Org.isShowList','1')
->groupby('Center.orgCd')
->orderby('Org.orgNm')
->get();
return view('member.memberList_test')
-> with('memberLists', $memberLists)
-> with('centerLists', $centerLists);
}
}
Routes
Route::group(['middleware' => ['web']], function () {
Route::get('member/test','MemberListTestController#search');
Route::post('member/test','MemberListTestController#search');
});
View
#extends('layouts.master')
#section('content')
<div class="container-fluid">
<p></p>
<div class="row"></div>
<div class="row">
<div class="col-md-4">
<form method="post" action="{{ url('member/test') }}" enctype="multipart/form-data">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<div class="form-group">
<select class="form-control" id="chosenCenter" name="chosenCenter">
<option value="" selected disabled> Choose Center</option>
#foreach ( $centerLists as $centerList )
<option value= {{ $centerList->orgCd }} #if (old('chosenCenter') == $centerList->orgCd) selected #endif > {{ $centerList->orgNm }}</option>
#endforeach
</select>
</div>
<div class="form-group">
<div class="input-group">
<input type="text" class="form-control"
placeholder="Search for First Name, Last Name... 'search all' for blank "
name="memberName">
<span class="input-group-btn">
<button class="btn btn-default " type="submit">Search</button>
</span>
</div>
</div>
</form>
</div>
</div>
<div class='row'></div>
<div class="row">
<table class="table table-striped table-condensed">
<thead>
<th>#</th>
<th>Center</th>
<th>First Name</th>
<th>Last Name</th>
<th>Date of Reg.</th>
<th>Recent Membership</th>
<th>Date of Membership Exp.</th>
<th>Latest Attendance</th>
<th>Cell Phone</th>
<th>Email</th>
<th>Member Group</th>
</thead>
<tbody>
<?php $count = 1; ?>
#foreach($memberLists as $memberList)
<tr>
<td>{{ (($memberLists->currentPage() - 1 ) * $memberLists->perPage() ) + $count++}}</td>
<td> {{ $memberList->orgNm }}</td>
<td> {{ $memberList->firstNm }} </td>
<td> {{ $memberList->lastNm }} </td>
<td> {{ $memberList->regDate }} </td>
<td> {{ $memberList->mshipNm }}</td>
#if (($memberList->rExpDt) >= date('y-m-d'))
<td> {{$memberList->rExpDt }}</td>
#else
<td> Expired on {{ $memberList->rExpDt }} </td>
#endif
<td>{{ $memberList->AttDt }}</td>
<td> {{ $memberList->phoneCell }}</td>
<td> {{ $memberList->email }}</td>
<td> {{ $memberList->groupNm }} </td>
</tr>
#endforeach
</tbody>
</table>
{!! $memberLists->render() !!}
</div>
</div>
#stop
You have to pass the parameters via GET and recover the parameters from the URL.
{!! $memberLists->appends(Input::all())->render() !!}
This will send you to page 2 and so on... with all the inputs values.
I found a video in laracasts that explains all the built-in pagination options for your blade template in laravel 5.2 :
https://laracasts.com/lessons/crazy-simple-pagination
you will see that the correct way for a search page is:
{{ $memberLists->appends(Request::except('page'))->links() }}
This way it will keep the current url parameteres.
We know laravel has an update() method that update records through "put" http method. Everything works cool except when I try validating the new input values against a static $rules method in my User model.
Please have a look at my model
protected $guarded = ['id', 'admin'];
public static $rules = [
'name' => 'required|min:4',
'username' => 'required|min:3|alpha_num|unique:users',
'email' => 'required|email|unique:users',
'password' => 'required|alpha_num|between:5,12|confirmed',
'password_confirmation' => 'required|alpha_num|between:5,12',
'phone' => 'required|min:5|alpha_num',
'city' => 'required|min:2|alpha',
'town' => 'required|min:2|alpha_num',
'address' => 'required|min:5|alpha_num',
'blood' => 'required|min:2',
'img' => 'image|mimes:jpeg,jpg,bmp,png,gif',
'active' => 'integer',
'admin' => 'integer'
];
You see I have made email as unique to the user table. So, when I try to update the records, which are about the logged in user's profile information, if I update all the records along with the email address it works. But if I leave the email field as is, it throws the validation error saying the email address is already taken.
But I want laravel to validate only the updated fields so that users can update whatever they want or leave one or two as before.
Is there any way to accomplish that?
Please now check out the controller method that is responsible for updating the newly inputted data
//update the changes now
public function update($id) {
$user = User::find($id);
$validator = Validator::make(Input::all(), User::$rules);
$input = array_except(Input::all(), ['_method', 'password_confirmation']);
if( $validator->passes() ) {
$user->save($input);
return Redirect::to('donors/'.$user->username.'/profile')
->withMessage('Information Updated');
}
return Redirect::to('donors/'.$user->username.'/profile/edit')
->withMessage('Something went wrong! Please fix the errors.')
->withErrors($validator)
->withInput();
}
For understanding the scenario more clearly, I am adding the form from view and the route file snippet too.
Route
Route::put('donors/{id}', ['uses'=>'DonorsController#update']);
Views form
{{ Form::open(['url'=>'donors/'.$donor->id, 'method'=>'put', 'role'=>'form']) }}
<table class="table table-bordered donors-table">
<colgroup>
<col class="col-xs-1">
<col class="col-xs-7">
</colgroup>
<thead>
<tr>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>
<span class="text-green">Name</span>
</td>
<td>
{{ Form::text('name', $donor->name) }}
<span class="text-red input-error">{{ $errors->first('name') }}</span>
</td>
</tr>
<tr>
<tr>
<td>
<span class="text-green">Email</span>
</td>
<td>
{{ Form::email('email', $donor->email) }}
<span class="text-red input-error">{{ $errors->first('email') }}</span>
</td>
</tr>
<tr class="odd">
<td>
<span class="text-green">New Password</span>
</td>
<td>
{{ Form::password('password', null) }}
<span class="text-red input-error">{{ $errors->first('password') }}</span>
</td>
</tr>
<tr class="odd">
<td>
<span class="text-green">Confirm New Password</span>
</td>
<td>
{{ Form::password('password_confirmation', null) }}
<span class="text-red input-error">{{ $errors->first('password_confirmation') }}</span>
</td>
</tr>
<tr class="odd">
<td>
<span class="text-green">Blood Group</span>
</td>
<td>
{{ Form::text('blood', $donor->blood) }}
<span class="text-red input-error">{{ $errors->first('blood') }}</span>
</td>
</tr>
<tr>
<tr class="odd">
<td>
<span class="text-green">Address</span>
</td>
<td>
{{ Form::text('address', $donor->address) }}
<span class="text-red input-error">{{ $errors->first('address') }}</span>
</td>
</tr>
<tr class="odd">
<td>
<span class="text-green">City</span>
</td>
<td>
{{ Form::text('city', $donor->city) }}
<span class="text-red input-error">{{ $errors->first('city') }}</span>
</td>
</tr>
<tr class="odd">
<td>
<span class="text-green">Town</span>
</td>
<td>
{{ Form::text('town', $donor->town) }}
<span class="text-red input-error">{{ $errors->first('town') }}</span>
</td>
</tr>
<tr class="odd">
<td>
<span class="text-green">Phone</span>
</td>
<td>
{{ Form::text('phone', $donor->phone) }}
<span class="text-red input-error">{{ $errors->first('phone') }}</span>
</td>
</tr>
<tr>
</tbody>
</table>
<p class="submit clearfix">
{{ Form::submit('Update', ['class'=>'btn btn-success pull-left']) }}
{{ link_to('donors/'.$donor->username.'/profile', 'Cancel', ['class'=>'pull-right btn btn-danger']) }}
</p>
{{ Form::close() }}
Did I miss anything please?
Let me know if I should show any other snippet of my codes.
For updating you need to change the email rule ever so slightly. If as part of the Unique rule you pass the field to check and then a value it won't complain that the value is already taken.
In your case update your controller by placing the following just before you do the validation:
User::$rules['email'] = 'required|email|unique:users,email,' . Input::get['email'];
Your validation should now pass as you have told laravel that the email should be unique but that you will accept the current email address.
Either do
$user->update($input);
or
// this is exactly what `update()` method does.
$user->fill($input)->save();
And adjust validation rules as well
'email' => 'unique:users,email_address,10'
where 10 is ID of current model instance. To achieve this, you need to parse rules in some way.