In my routing if i remove the {page} prefix it works completely fine but when i put it i get an error. For other it is working fine but it is not working for this route: Route::get('/{categories}', 'AdminVisible\CostIncludeController#index');
My AdminPageController:
public function index($page)
{
$page = Page::where('Pages_Slug_Name',$page)->firstorFail();
$pages = Page::all();
return view('admin.pages.page',[
'page' => $page,
],compact('pages'));
}
My CostIncludeController:
public function index($categories){
$pages = Page::all();
$packages = Package::where('slug',$categories)->first();
return view('admin.pages.costinclude',[
'packages' => $packages,
],compact('pages'));
}
My Route:
Auth::routes(['register' => false,'login' => false]);
Route::prefix('admin')->group(function() {
Route::get('/')->name('login')->uses('Auth\LoginController#showLoginForm');
Route::post('/')->name('login')->uses('Auth\LoginController#login');
Route::get('/dashboard', 'AdminVisible\HomeController#index')->name('admin.dashboard');
Route::prefix('pages')->group(function() {
Route::get('/','AdminVisible\AdminPageController#pages')->name('pages');
Route::prefix('{page}')->group(function() {
Route::get('/','AdminVisible\AdminPageController#index')->name('page');
Route::get('/banner', 'AdminVisible\BannerController#index');
Route::get('/why-with-us', 'AdminVisible\WhyWithUsController#index');
Route::get('/testimonials', 'AdminVisible\TestimonialsController#index');
Route::get('/about', 'AdminVisible\AboutController#index');
Route::get('/about-why-with-us', 'AdminVisible\AboutWhyWithUsController#index');
Route::get('/general-information', 'AdminVisible\PackageController#index');
Route::get('/package-program', 'AdminVisible\PackageController#index');
Route::get('/cost-exclude', 'AdminVisible\PackageController#index');
Route::prefix('cost-include')->group(function() {
Route::get('/', 'AdminVisible\PackageController#index');
Route::get('/{categories}', 'AdminVisible\CostIncludeController#index');
});
});
});
});
My blade.php file:
#extends('layouts.app')
#section('style')
<link href="{{ asset('css/Admin/sql-data-viewer.css') }}" rel="stylesheet">
<style></style>
#endsection
#section('content')
<section class="data-viewer">
<div class="d-flex justify-content-between">
<h3>Select Package to change</h3>
<button type="button" class="btn add-data text-white rounded-pill">Add <i class="fas fa-plus"></i></button>
</div>
<table>
<thead>
<tr class="data-head">
<td scope="col" style="width: 5%"><input type="checkbox"></td>
<th scope="col" style="width: 8.7%">Id</th>
<td scope="col">Includes</td>
</tr>
</thead>
<tbody>
#foreach ($packages->costIncludes as $include)
<tr class="data">
<td scope="col" style="width: 6.5%"><input type="checkbox"></td>
<th scope="col" style="width: 10%;">{{$include->id}}</th>
<td scope="col" class="text-justify" style="width:696px">{{Str::limit($include->Cost_Include,100)}}</td>
</tr>
#endforeach
</tbody>
</table>
</section>
#endsection
With {page} prefix:
Without {page} prefix:
With {page} prefix when i do dd():
Without {page} prefix when i do dd():
In your CostIncludeController#index, add the new variable. The router is expecting you to handle two variables.
public function index($page, $categories){
$pages = Page::all();
$packages = Package::where('slug',$categories)->first();
return view('admin.pages.costinclude',[
'packages' => $packages,
],compact('pages'));
}
You can confirm the cause of the error by doing a dd($categories) inside your controller function in both cases.
It seems we need to pass $page parameter in the CostIncludesController. This same question is answered in this post:
I am having trouble with my route in laravel
Related
So I have a table on blade view file, I have successfully exported it into the excel file. Now I want to export without exporting the 'Actions" column. How can I do that?
I have attached my code and blade file below, it works perfectly. I just want to export everything except the Actions Column as it contains Buttons for Database Operations
THIS IS MY EXPORT CLASS CODE:
public function view(): View
{
return view ('ims.view_inventory_history_table', [
'data' => inbound_history::all()
]);
}
public function headings(): array
{
return [
'ID',
'Warehouse',
'SKU',
'Child SKU',
'Units',
'Invoice No.',
'Container No.',
'Entry Date'
];}
/**
* #return array
*/
public function registerEvents(): array
{
return [
AfterSheet::class => function(AfterSheet $event) {
$cellRange = 'A1:W1'; // All headers
$event->sheet->getDelegate()->getStyle($cellRange)->getFont()->setSize(14);
},
];
}}
THIS IS MY CONTROLLER FUNCTION:
public function export_view()
{
return Excel::download(new inboundHistory(), 'inboundHistory.xlsx');
}
THIS IS MY ROUTE:
Route::Get('inbound_history/export_view' ,'imsController#export_view')->name('inbound_history.export_view');
THIS IS MY BLADE TABLE VIEW:
<table id="datatables" class="table table-striped table-no-bordered table-hover" cellspacing="0" width="100%" style="width:100%">
<thead>
<tr>
<th style="width:5%">ID</th>
<th>Warehouse</th>
<th>SKU</th>
<th>Child SKU</th>
<th>Cases</th>
<th>Units</th>
<th>Invoice No.</th>
<th>Container No.</th>
<th>Entry Date</th>
<th class="disabled-sorting text-right" style="width:12%">Actions</th>
</tr>
</thead>
<tbody>
#foreach ($data as $row)
<tr>
<td>{{$row['id']}}</td>
<td>{{$row['warehouse']}}</td>
<td>{{$row['sku_parent']}}</td>
<td>{{$row['sku_child']}}</td>
<td>{{$row['total_cases']}}</td>
<td>{{$row['total_units']}}</td>
<td>{{$row['invoice_no']}}</td>
<td>{{$row['container_no']}}</td>
<td>{{$row['date_rec']}}</td>
<td class="td-actions text-right">
{{-- <a rel="tooltip" class="btn btn-success btn-link" href="{{action('imsController#edit',$row['id'])}}">
<i class="material-icons">edit</i></a> --}}
<a rel="tooltip" class="btn btn-danger btn-link" href="{{action('imsController#destroy',$row['id'])}}" onclick = "if (! confirm('Confirm: Press OK to delete the Entry.')) { return false; }"style="color: red;">
<i class="material-icons">close</i></a>
</td>
</tr>
#endforeach
</tbody>
I don't know if I got everything correctly, but why don't you do something like this:
Pass an additional variable to your blade template like $isView, when you want to create a view for the user.
And in your blade.php template you do something like this:
#isset($isView)
<th class="disabled-sorting text-right" style="width:12%">Actions</th>
#endisset
// do the same #isset test for the corresponding <td> element
When you want to render it to excel you just don't pass this variable and the column is not rendered.
I wont to fetch data from database and show them in a view page as a table. I tried so many ways and didn't work. Also I have used member adding form as a model in my home.blade.php and it works fine.
here is my home.blade.php
<!-- show tasks -->
<div class="container-fluid">
<div class="container mt-4">
<table class="table">
<thead class="thead-dark">
<tr>
<th scope="col">ID</th>
<th scope="col">Task</th>
<th scope="col">Assigned Date</th>
<th socpe="col">Sign-off Date</th>
<th socpe="col">Edit/Delete</th>
</tr>
</thead>
#foreach($tasks as $task)
<tr>
<td>{{$task->id}}</td>
<td>{{$task->task}}</td>
<td>{{$task->assigned_date}}</td>
<td>{{$task->end_date}}</td>
<td>
Delete
Edite
</td>
</tr>
#endforeach
</table>
</div>
</div>
<!-- end Show tasks -->
here is my taskController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\task;
class taskController extends Controller
{
public function store(Request $request){
$this->validate($request,[
'task'=>['required', 'max:100', 'min:5'],
'assignedDate' => ['required', 'date'],
'endDate' => ['required', 'date'],
]);
$task = new task;
$task->task = $request->task;
$task->assigned_date = $request->assignedDate;
$task->end_date = $request->endDate;
$task->save();
return redirect()->back()->with('message', 'Task added successfuly');
}
public function getdata()
{
$data=task::all();
return view('home')->with('tasks', $data);
}
}
and here is my web.php
<?php
use Illuminate\Support\Facades\Route;
Route::get('/', function () {
return view('welcome');
});
Route::post('/saveTask', 'taskcontroller#store');
Auth::routes();
Route::get('/home', 'HomeController#index')->name('home');
So, What am I doing wrong here? Can somebody please explain me?
Change your Last Route to
Route::get('/home', 'HomeController#getdata')->name('home');
I am trying to use controller's update function on my dashboard.blade.php page, but when I press on "Save" it switches to show.blade.php page instead of updating.
My dashboard.blade.php page:
#if(count($posts) > 0 )
<table class="table table-striped">
<tr>
<th>Title</th>
<th>Body</th>
<th>Employee Number</th>
<th>Edit</th>
<th>Save</th>
</tr>
#foreach($posts as $post)
<tr>
<td>{{$post->title}}</td>
<td><input type='text' name='body'class='form-control' value='{{$post->body}}'></td>
<td>{{$post->employee_no}}</td>
<td><a href="{{ action("PostsController#update", $post->id) }}" >Save</a></td>
<td>Edit</td>
</tr>
#endforeach
</table>
#else
<p>You Have No Posts</p>
#endif
My update function on PostsController.php page:
public function update(Request $request, $id)
{
$this->validate($request,[
//'title' => 'required',
'body' => 'required'
]);
//Update Post
$post = Post::find($id);
//$post->title = $request->input('title');
$post->body = $request->input('body');
$post->save();
return redirect('/posts')->with('success','Post Updated');
}
I read that "action" will go to the first route that matches the pattern, but I do not know how to solve this problem.
My web.php page:
Route::get('/', 'PagesController#index');
Route::get('/about', 'PagesController#about');
Route::get('/services', 'PagesController#services');
Route::resource('posts','PostsController');
Auth::routes();
Route::get('/dashboard', 'DashboardController#index');
How can I call the update function correctly from dashboard.blade.php page?
To update data you have to use form with put method.
and route will be like this,
Route::put('dashboard/update/{id}',[
'uses' => 'DashboardController#update',
'as' => 'dashboard.update'
]);
For more Laravel Routing
Hope it helps :)
You can solve this by using form submit with hidden PUT method.
<form action="{{ url('customers') }}/{{$data['customer']->id}}" method="POST">
<input type="hidden" name="_method" value="PUT">
#csrf
</form>
How about having a simple form for each row in the table :
#if(count($posts) > 0 )
<table class="table table-striped">
<tr>
<th>Title</th>
<th>Body</th>
<th>Employee Number</th>
<th>Edit</th>
<th>Save</th>
</tr>
#foreach($posts as $post)
<tr>
<td>{{$post->title}}</td>
<td>{{$post->employee_no}}</td>
<td>
<!-- Form for each row -->
<form action="{{ route("posts.update", [ 'post' => $post->id ]) }}" method="POST">
#method('PUT')
#csrf
<input type='text' name='body'class='form-control' value='{{$post->body}}'></td>
<button type="submit">Save</button>
</form>
<!-- Form for each row -->
<td>Edit</td>
</tr>
#endforeach
</table>
#else
<p>You Have No Posts</p>
#endif
This is Controller. I named it CartController
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Gloudemans\Shoppingcart\Facades\Cart;
use App\Product;
class CartController extends Controller
{
public function index()
{
$cartItems=Cart::content();
return view('cart.index', compact('cartItems'));
}
public function edit($id)
{
$product=Product::find($id);
Cart::add($id,$product->name,'1',$product->price);
}
This is my welcome.blade.php. This is the page where I display all my Items.
<div class="row">
#forelse($books->chunk(4) as $chunk)
#foreach($chunk as $book)
<div class="column-prod">
<a href="{{url('view')}}">
<div class="card-prod">
<center><img src="{{url('images',$book->image)}}" style="width: 300px; height: 300px;"></center> </a>
<div class="container-prod">
<h2></h2>
<p class="title">{{$book->name}}</p>
<p class="price">₱ {{$book->price}}</p>
<p><i class="fas fa-cart-arrow-down"></i>Add to Cart</button></p>
<p><button class="button"><i class="fas fa-heart"></i> Add to Wishlist</button></p>
</div>
</div>
</div>
#endforeach
#empty
<h3> No Books </h3>
#endforelse
</div> <!--Div all end-->
This is the codes of my Cart Page. When the user click add to cart in the welcome page, his/her chosen items will be place in this page.
<h3> Cart Items </h3>
<!--TABLE NAMESSS-->
<table class="table table-hover">
<thead>
<tr>
<th scope="col">Image</th>
<th scope="col">Name</th>
<th scope="col">Price</th>
<th scope="col">Quantity</th>
</tr>
</thead>
<tbody>
#foreach($cartItems as $cartItem)
<li>{{$cartItem->name}}</li>
<tr>
<td>{{url('images',$cartItem->image)}}</td>
<td>{{$cartItem->name}}</td>
<td>{{$cartItem->price}}</td>
<td>{{$cartItem->qty}}</td>
</tr>
#endforeach
</tbody>
</table>
This is my route.
Route::get('/', function () {
return view('welcome')->with(['books' => \App\Product::all()]);
});
Route::get('/cart','ShopController#cart');
Route::get('/signin','ShopController#signin');
Route::resource('/cart','CartController');
Route::get('/wishlist','ShopController#wish');
Auth::routes();
Route::get('/logout', 'Auth\LoginController#logout');
Route::get('/home', 'HomeController#index');
Route::group(['prefix' => 'admin', 'middleware' => 'auth'], function(){
Route::get('/',function(){
return view('admin.index');
})->name('admin.index');
Route::resource('product','ProductsController');
Route::resource('category','CategoriesController');
});
Route::get('/categ', function(){
return view ('admin.category.categ_index');
});
I'm confused I don't know how to fix my error. This is the complete error that the system return.
"htmlspecialchars() expects parameter 1 to be string, object given (View: C:\xampp\htdocs\Shop\resources\views\welcome.blade.php)"
I hope you can help me in solving this. Your answers are very much appreciated.
I'm trying to update my 'pay' record in the DB after pressing a button in a table row, but it shows this error when pressing the button:
ErrorException in 0db55b8fee884912074e1a4700061051aeb18bcc.php line
15: Undefined variable: users (View:
/Users/mauricio/code/cnr/resources/views/pages/users.blade.php)
I don't know why it gives me that error when I have use the users variable before in the blade file.
Here is my Registration Controller:
<?php
namespace App\Http\Controllers;
use DB;
use App\User;
class RegistrationController extends Controller
{
public function updatePay(User $id)
{
DB::table('users')->where('id', $id)->update(['pay' => 1]);
return view('pages.users');
}
}
Welcome controller:
public function usersAdmin()
{
$users = DB::table('users')->get();
return view('pages.users', compact('users'));
}
Routes file:
// for admin only
Route::get('/users', 'WelcomeController#usersAdmin');
Route::post('/users/{id}', 'RegistrationController#updatePay');
Here is my view
#extends('layouts.master')
#section('content')
<table class="highlight">
<thead>
<tr>
<th data-field="id" hidden="">ID</th>
<th data-field="name">Nombre</th>
<th data-field="last_name">Apellidos</th>
<th style="text-align: right;">Acciones</th>
</tr>
</thead>
<tbody>
#foreach($users as $user)
<tr>
<td>{{$user->id}}</td>
<td>{{$user->name}}</td>
<td>{{$user->last_name}}</td>
<td style="text-align: right; width: 30em">
#if( $user->isAdmin )
{{"ADMINISTRADOR"}}
#elseif( $user->pay )
<a class="waves-effect waves-light btn yellow darken-2"><i class="material-icons left" style="margin:0">create</i></a>
<a class="waves-effect waves-light btn red darken-1"><i class="material-icons left" style="margin:0">delete</i></a>
#else
<form method="POST" action="/users/{{$user->id}}">
{{ csrf_field() }}
<button type="submit" class="waves-effect waves-light btn green lighten-1"><i class="material-icons left" style="margin:0">done</i></button>
</form>
#endif
</td>
</tr>
#endforeach
</tbody>
</table>
#endsection
You need to retrieve users and send it to the view similar like this:
Controllers:
public function methodName()
{
$users = User::all();
return view('path.to.view')->with(compact('users'));
}
Also, You have two choice to use:
First
public function updatePay($id)
Second
public function updatePay(User $user)
{
DB::table('users')->where('id', $user->id)->update(['pay' => 1]);
and instead of return view('pages.users'); use return redirect()->url('users'); in the updatePay method.