"Class App\Http\Controllers\Frontend\FrontendController does not exist" - php

I installed a laravel script. but a page not worked and appear
Trying to get property 'name' of non-object (View:
/mylocal/core/resources/views/admin/users/servicePrice.blade.php)
for this line:
<th>{{ $item->service->name }}</th>
this is the file codes:
<div class="tile">
#include('admin.layouts.flash')
<h3 class="tile-title">Service Price Details</h3>
<form method="post" action="{{ route('store.service.price', $user_id) }}">
#csrf
#method('PUT')
<table class="table table-hover">
<tbody>
#foreach($items as $item)
<tr>
<th>{{ $item->category->name }}</th>
<th>{{ $item->service->name }}</th>
<td>
<div class="input-group">
<input type="hidden" name="id[]" value="{{ $item->id }}">
<input class="form-control" type="text" name="price[]" value="{{ $item->price }}">
<div class="input-group-append">
<span class="input-group-text">{{ $general->currency_symbol }}</span>
</div>
</div>
</td>
</tr>
#endforeach
</table>
<div class="tile-footer">
<button class="btn btn-primary btn-block btn-lg" type="submit"><i
class="fa fa-fw fa-lg fa-check-circle"></i>Save
</button>
</div>
</form>
</div>

Check your relation return a object or not.
<th>
#if($item->service)
{{ $item->service->name }}
#endif
</th>

You didn't share the content of array $items.Please make sure you have a service array in $items array and also make sure the name variable exists in service array.
and can you show me the result of this:
var_dump($items);

Related

Error with my controller and ajax function

I used AJAX to create live search function, but I have meet the error on my controller. I think it's syntax error on the last td #method('DELETE'), I don't know how to fix it, can anyone help me ?
public function search(Request $request)
{
$output = '';
$users = User::where('name','LIKE','%'.$request->keyword.'%')->get();
foreach($users as $user)
{
$output += '<tr>
<td>
<div class="d-flex px-2 py-1">
<div>
<img src="'. asset('storage/users/' . $user->image) .'"
class="avatar avatar-sm me-3 border-radius-lg" alt="user1">
</div>
<div class="d-flex flex-column justify-content-center">
<h6 class="mb-0 text-sm">{{ $user->name }}</h6>
<p class="text-xs text-secondary mb-0">'. $user->email .'</p>
</div>
</div>
</td>
<td>
<p class="text-xs font-weight-bold mb-0">'. $user->date_of_birth .'</p>
<p class="text-xs text-secondary mb-0">'. $user->phone .'</p>
</td>
<td class="align-middle text-center">
<span
class="text-secondary text-xs font-weight-bold">'. $user->address .'</span>
</td>
<td class="align-middle">
<form action="" method="POST">
{{ csrf_field() }}
#method('DELETE')
<button class="btn btn-danger" data-toggle="tooltip"
data-original-title="Delete user" type="submit">Delete</button>
</form>
</td>
</tr>';
}
return response()->json($output);
}
One clean solution to achieve what you need is to render the HTML as blade file using view('')->render() instead of building it on the controller
Create a new view file at resources/views/partials/user-search.blade.php and move your HTML to it
#foreach ($users as $user)
<tr>
<td>
<div class="d-flex px-2 py-1">
<div>
<img src="{{ asset('storage/users/'.$user->image) }}"
class="avatar avatar-sm me-3 border-radius-lg" alt="user1">
</div>
<div class="d-flex flex-column justify-content-center">
<h6 class="mb-0 text-sm">{{ $user->name }}</h6>
<p class="text-xs text-secondary mb-0">{{ $user->email }}</p>
</div>
</div>
</td>
<td>
<p class="text-xs font-weight-bold mb-0">{{ $user->date_of_birth }}</p>
<p class="text-xs text-secondary mb-0">{{ $user->phone }}</p>
</td>
<td class="align-middle text-center">
<span class="text-secondary text-xs font-weight-bold">{{ $user->address }}</span>
</td>
<td class="align-middle">
<form action="" method="POST">
{{ csrf_field() }}
#method('DELETE')
<button class="btn btn-danger" data-toggle="tooltip"
data-original-title="Delete user" type="submit">Delete</button>
</form>
</td>
</tr>
#endforeach
then modify your Controller search method to something like:
public function search(Request $request)
{
$users = User::where('name', 'LIKE', '%'.$request->keyword.'%')->get();
$output = view('partials.user-search')->with(['users' => $users])->render();
return response()->json($output);
}
Before I propose my fixes note that #ferhsom solution is a really a cleaner and better way to achieve what you need. But still the error in your code need to be pin pointed.
Errors
First the litteral string
Everything written between single quotes is considered as a string (literally) so no function call or variable will work.
The following string as HTML will give you this: enter image description here:
'
<td>
<form action="" method="POST">
{{ csrf_field() }}
#method("DELETE")
<button type="submit">Delete</button>
</form>
</td>
'
But what you need is hidden inputs with the keys _method and _token.
Second no Blade rendering
#method and #csrf are a Blade directives which will not make any sense if it doesn't pass through the rendering process.
Solution
Replace #method('DELETE') with:
'<input type="hidden" name="_method" value="DELETE">'
For #csrf or {{ csrf_field() }} do:
'<input type="hidden" name="_token" value="' . csrf_token() . '">'
Or
'' . csrf_field() . ''

laravel 8 crude operation not showing

i have laravel connected
to database mysql
when i do insert/update i find it on the mysql table
but the page show data does not reflect the change
my page is products.
the web route:
<?php use Illuminate\Support\Facades\Route; use App\Http\Controllers\ProductController;
Route::get('/', function () {
return view('welcome'); });
Auth::routes();
Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home');
Route::resource('products', ProductController::class);
the show index.blade.php page :
#extends('products.layout')
#section('content')
<div class="row">
<div class="col-lg-12 margin-tb">
<div class="pull-left">
<h2>Laravel 8 CRUD Example from scratch - ItSolutionStuff.com</h2>
</div>
<div class="pull-right">
<a class="btn btn-success" href="{{ route('products.create') }}"> Create New Product</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>Details</th>
<th width="280px">Action</th>
</tr>
#foreach ($products as $product)
<tr>
<td>hi</td>
<td>{{ $product->name }}</td>
<td>{{ $product->detail }}</td>
<td>
<form action="{{ route('products.destroy',$product->id) }}" method="POST">
<a class="btn btn-info" href="{{ route('products.show',$product->id) }}">Show</a>
<a class="btn btn-primary" href="{{ route('products.edit',$product->id) }}">Edit</a>
#csrf
#method('DELETE')
<button type="submit" class="btn btn-danger">Delete</button>
</form>
</td>
</tr>
#endforeach
</table>
#endsection
does any one can give me the reason why change not reflected
enter image description here
In your controller, after updating product, try to do:
return redirect()->back();

Get the value of table data from the same row

I'm trying to explain my question the best I can, so sorry if it's a bit confusing.
I have in my HTML Table, with table row, and table data, each row is filled with data from data base, and the table is automatically generated.
Example is below.
<thead>
<tr>
<th>Place ID</th>
<th>Map Name</th>
<th>Place Name</th>
<th>Price 1</th>
<th>Price 2</th>
<th>Price 3</th>
<th>Price 4</th>
#if (Auth::user()->role == "admin")
<th>Action</th>
<th>Booking</th>
#endif
</tr>
</thead>
<div id="preloader"></div>
<tbody id="hidden_table_processing">
#foreach ($places as $place)
<tr>
<td>{{ $place->place_id }}</td>
<td>{{ $place->map_name }}</td>
<td>{{ $place->place_name }}</td>
<td>{{ $place->price1 }} €</td>
<td>{{ $place->price2 }} €</td>
<td>{{ $place->price3 }} €</td>
<td>{{ $place->price4 }} €</td>
For booking table head, its filled with a quick booking button, that is supposed to get the Place ID of the data from the same raw, and shows it inside a popup, bellow is the code that creates the popup and fills the data.
<td>{{-- status print --}}
#if ($place->status==0)
<!-- Trigger the modal with a button -->
Quick Book
<!-- Modal -->
<div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<form method=POST action="{{ route('admin.place.quickbooking') }}">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Quick Book</h4>
</div>
<div class="modal-body">
#csrf
<div class="form-group">
<label for="usr">ID:</label>
<input type="text" class="form-control" value="{{ $place->place_id }}" id="qBookingID" name="qID" readonly>
<label for="usr">Full Name:</label>
<input type="text" class="form-control" value="{{ Auth::user()->name }}" id="qBookingFullName" name="qFullName">
<label for="usr">Number of Guests:</label>
<input type="number" class="form-control" id="qBookingNumberOfGuests" name="qNumberOfGuests">
<label for="usr">Number of Babies:</label>
<input type="number" class="form-control" id="qBookingNumberOfBabies" name="qNumberOfBabies">
<label for="usr">Check In:</label>
<input type="text" class="form-control" value="{{ session()->get('startingRange') }}" id="qBookingStartDate" name="qStartDate" readonly>
<label for="usr">Check Out:</label>
<input type="text" class="form-control" value="{{ session()->get('endingRange') }}" id="qBookingEndDate" name="qEndDate" readonly><br>
<label for="usr">Map Name: {{ $place->map_name }}</label><br>
<label for="usr" id="qBookingCreatorName" name="qCreatorName">Booked By: {{ Auth::user()->name }}</label>
</div>
{{-- Book --}}
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal" style="color: red; border: 1px solid red;" >Close</button>
<button type="submit" class="btn btn-default" style="color: green; border: 1px solid green;" type="submit">Book</button>
</div>
</div>
</form>
</div>
</div>
#endif
#if ($place->status==-1)
<p>Disabled</p>
#endif
#if ($place->status==2)
<p style="color:red;">Busy</p>
#endif
</td>
My problem is that the auto filled ID is only being filled by the First Data, as no matter which row I click on, the ID stays the same "the first ID from the table"
Any idea what might be causing this, or am I missing something very obvious?
THank you for your help.
For your case the better choice is pass the object place to a function using javascript, every time that you give click the modal appears with the data
that you want to edit or show.
Edit
#push('script')
<script>
$(document).ready(function () {
$('body').on('click', '#editModal', function (event) {
event.preventDefault();
let id = $(this).data('id');
console.log(id)
let name = {{ Auth::user()->name }}
let startdate = {{ session()->get('startingRange') }}
let enddate = {{ session()->get('endingRange') }}
let bookname = 'Booked By:' + name
$.get('place/' + id + '/edit', function (data) {
$("#qBookingID").val(data.data.place_id);
$(#qBookingFullName").val(name);
$("#qBookingStartDate").val(startdate);
$("#qBookingEndDate").val(enddate);
$("#qBookingCreatorName").val(bookname);
$('#Mymodal').modal('show');
})
});
});
</script>
#endpush

Undefined variable: user_id in Laravel view

The Routes
Route::get('/adminContacts/{user_id}', 'AdminContactsController#index')->name('adminContacts.index')->middleware('is_admin');
Route::get('/adminContacts/{user_id}/create', 'AdminContactsController#create')->name('adminContacts.create')->middleware('is_admin');
adminContactController
public function index($user_id)
{
// Confirm User exists
User::findOrFail($user_id);
$filter = request('filter', NULL);
$contacts = NULL;
if ($filter == NULL)
$contacts = Contacts::query()->where('owner_id', $user_id)->sortable()->paginate(5);
else
$contacts = Contacts::query()->where('owner_id', $user_id)->where('name', 'like', '%'.$filter.'%')
->orWhere('number', 'like', '%'.$filter.'%')
->sortable()->paginate(5);
return view('adminContacts.index')->withContacts($contacts)->withUserId($user_id);
}
/**
* Show the form for creating a new resource.
*
* #return \Illuminate\Http\Response
*/
public function create($user_id)
{
return view('adminContacts.create')->withUserId($user_id);
}
index.blade.php
<div class="container">
<h1 class="jumbotron">Sample Phone Book</h1>
Add Contact
</div>
<!--Search Field -->
<div class="container">
<form method="GET" action="{{ route('adminContacts.index') }}">
<input type="text" name='filter' class='input' placeholder='Search' value="{{ request('filter') }}">
#if (request('filter'))
<a class="btn btn-primary btn-sm" href="{{ route('adminContacts.index') }}">X</a>
#endif
</form>
</div>
<!-- Table -->
<div class="container">
<div class="row" >
<table class="table table-hover" id="contactsTable">
<thead>
<tr>
<th>#</th>
<th>#sortablelink('name', 'Contact Name')</th>
<th>#sortablelink('number', 'Phone Number')</th>
<th>
<button class="btn btn-primary btn-sm">Prepend</button>
</th>
</tr>
</thead>
<!--Loop through all the cutomers and output them on the table-->
#foreach($contacts as $contact)
<tbody>
<tr>
<td>{{ $contact->id }}</td>
<td>{{ $contact->name }}</td>
<td>{{ $contact->number }}</td>
<td>
View
</td>
</tr>
</tbody>
#endforeach
</table>
{!! $contacts->appends(\Request::except('page'))->render() !!}
</div>
</div>
The error is:
Undefined variable: user_id (View: D:\laragon\www\SampleContacts\resources\views\adminContacts\index.blade.php)
Am I missing something? The idea is to pass the $user_id to the adminContact.create form where i can use it to set
$contact->owner_id = $user_id;
so the entered contact apears under that users table.
I don't think you can pass variables into your view like you're doing now.
In your controller, try changing this line:
return view('adminContacts.index')->withContacts($contacts)->withUserId($user_id);
To this:
return view('adminContacts.index')->with('contacts', $contacts)->with('user_id', $user_id);
You could explicitly name the variable when passing it to the view, either this way
return view('adminContacts.index')->with('user_id', $user_id);
Or
return view('adminContract.index', compact('user_id'));
I'm not sure what the name of the variable becomes when passed to the view via withUserId, but I'm guessing this is the issue.
Found the problem.
#extends('layouts.app')
#section('content')
<div class="container">
<h1 class="jumbotron">Sample Phone Book</h1>
Add Contact
</div>
<!--Search Field -->
<div class="container">
<form method="GET" action="{{ route('adminContacts.index', $user_id) }}">
<input type="text" name='filter' class='input' placeholder='Search' value="{{ request('filter') }}">
#if (request('filter'))
<a class="btn btn-primary btn-sm" href="{{ route('adminContacts.index', $user_id) }}">X</a>
#endif
</form>
</div>
<!-- Table -->
<div class="container">
<div class="row" >
<table class="table table-hover" id="contactsTable">
<thead>
<tr>
<th>#</th>
<th>#sortablelink('name', 'Contact Name')</th>
<th>#sortablelink('number', 'Phone Number')</th>
<th>
<button class="btn btn-primary btn-sm">Prepend</button>
</th>
</tr>
</thead>
<!--Loop through all the cutomers and output them on the table-->
#foreach($contacts as $contact)
<tbody>
<tr>
<td>{{ $contact->id }}</td>
<td>{{ $contact->name }}</td>
<td>{{ $contact->number }}</td>
<td>
View
</td>
</tr>
</tbody>
#endforeach
</table>
{!! $contacts->appends(\Request::except('page'))->render() !!}
</div>
</div>
#endsection
Anywhere where there is a {{ route('adminContacts.index') }} it also needed the $user_id to be passed along with it because I'm also using it in the routes as '/adminContacts/{user_id}'
Thank you for all the help.

Laravel 5.2 pagination issue with select box

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.

Categories