In controller;
public function list_of_approved_policies(){
dd("I am here");
die();
}
In route
Route::get('/listofapprovedpolicies','MerchantDashboardController#list_of_approved_policies');
When I calling /listofapprovepolicies Laravel return just white blank page. How can i solve this problem ?
try to change the route's declared sintax to
use App\Http\Controllers\MerchantDashboardController;
.....
Route::get('/listofapprovedpolicies',[MerchantDashboardController::class, 'list_of_approved_policies')->name('policies_list');
and in controller make the dump
public function list_of_approved_policies()
{
dd('dumped');
}
Related
I'm trying to set up a basic Laravel CRUD application, and I'm getting stuck setting up the pages for each action.
When I visit the route case/create, it opens the page for show instead.
routes/web.php
use App\Http\Controllers\HospitalCase as HospitalCase;
Route::controller(HospitalCase::class)->group(function() {
Route::get('/cases','index')->middleware('auth')->name('cases');
Route::get('/case/{id}','show')->middleware('auth');
Route::get('/case/create','create')->middleware('auth');
Route::post('/case/create','store')->middleware('auth');
Route::get('/case/edit/{$id}','edit')->middleware('auth');
Route::post('/case/edit/{$id}','update')->middleware('auth');
Route::get('/case/delete/{$id}','destroy')->middleware('auth');
});
HospitalCase.php controller
class HospitalCase extends Controller
{
function index()
{
echo 'index';
}
function create()
{
echo 'create';
}
function show($id)
{
echo 'show';
}
function store()
{
// validation rules
}
function edit($id)
{
return view('case/edit');
}
function update($id)
{
}
function destroy($id)
{
}
}
This is what I see on the browser:
I have been trying to figure this out for hours and can't think of what I'm doing wrong.
PS: The auth middleware is using laravel breeze (unmodified)
The reason it's showing the show route is because you defined
Route::get('/case/{id}','show')->middleware('auth');
before it, therefore, it's matching case/create as show('create')
Try defining the route afterwards.
Route::get('/case/create','create')->middleware('auth');
Route::post('/case/create','store')->middleware('auth');
Route::get('/case/{id}','show')->middleware('auth');
Just want to reiterate what #TimLewis has suggested, I think you need to put this route:
Route::get('/case/create','create')->middleware('auth');
Above this route:
Route::get('/case/{id}','show')->middleware('auth');
But you could try using Laravel’s route resource so you don’t need to write out all the routes -
use App\Http\Controllers\HospitalCaseController;
Route::resource('case', HospitalCaseController::class);
im trying to call a function from another route in laravel php.
I have the route "welcome"
Route::get('/', function () {
return view('welcome');
});
where im calling this extends (sidebar)
#extends('layouts.guestnavbar')
i want to see if my table notifications is empty or not so i made this controller
class GuestNavbarController extends Controller
{
public function isempty(){
$notif = Notification::first();
if(is_null($notif)) {
return view('layouts.guestnavbar')->with("checkempty", "empty");
}else {
return view('layouts.guestnavbar')->with("checkempty", "not empty");
}
}
}
and i called the variable {{ $checkempty }} in my route guestnavbar
Route::get('/guestnavbar', [GuestNavbarController::class, 'isempty']);
and it works when im in the route guestnavbar
but doesnt work when im in the route welcome because i call the function in the route guestnavbar and in welcome he doesnt recognize the variable: checkempty
i need this function to be in the guestnavbar because i have to call it on other pages, not just in welcome page
I appreciate any help.
You don't need isempty inside controller, just add method isempty inside Notification model, you can use something like this inside Notification model:
public static function isEmpty(){
return Notification::first() ? true : false;
}
And then where you need to check if notification table is empty just call Notification::isEmpty()
I can't pass the data from the controller to the view in CodeIgniter 3. All the thing seem okay. Do I need to put the Controller's part in the index() method?
Donor_Model.php
function viewDonors() {
$query = $this->db->get('donors');
return $query;
}
Staff.php controller
public function viewDonors()
{
$this->load->Model('Donor_Model');
$data['donors'] = $this->Donor_Model->viewDonors();
$this->load->view('viewdonors', $data);
}
When I try to call the $data in the viewdonors.php view, it shows the $donors as undefined.
screenshot of viewdonors.php
#TimBrownlaw is right. Even though the IDE shows an error, the code runs without a problem.
You need to edit your model page to:-
function viewDonors() {
$query = $this->db->get('donors');
return $query->result();
}
As you want to loop through donors data in the view page so you need to return result function in the model.
I want to send my data from controller to xedit.blade.php, but I get the same error:
Undefined variable: users
in controller:
public function index3()
{
$users=User::all();
return view('xedit')->with('users' => $users);
}
Routes:
Route::get('admin/edit', function () {
return view('xedit');
})->name('edit');
Route::get('edit','Admin\UsersController#index3');
and I want to use $users in blade.Maybe there is a Route problem?
You have to change
Route::get('edit','Admin\UsersController#index3')->name('edit');
Use this code.
Route::get('/admin/edit','AdminController#index3')->name('edit');
It calls the AdminController's index3() and the function returns the view.
public function index3()
{
$users=User::all();
return view('xedit')->with('users' => $users);
}
The below code won't call the index3() in AdminController but returns
the view directly with empty data.
Route::get('admin/edit', function () {
return view('xedit');
})->name('edit');
maybe this route
Route::get('admin/edit', function () {
return view('xedit');
})->name('edit');
This route doesn't contain $users, maybe this is why it's undefined.
The problem is you are using the same view xedit for both of your routes admin/edit & /edit .
So, when you visit admin/edit $users variable in the xedit view file getting no value which means it's undefined. Try to check if $users variable is defined before using that.
I keep getting errors on this line of code and I am not sure what the problem is?
Here is the route:
Route::get('/samples', 'TestsController#index');
Here is the controller line that is causing the error:
public function index()
{
return $this->makeView('samples.create');
}
Here is the error: Method [makeView] does not exist.
try with
public function getIndex()
{
return View::make('samples.create');
}
It should be
public function index()
{
return $this->make::View('samples.create');
}
You forgot the :: between make and View.
Im not aware of a 'makrView' method, but this is how a view is traditionally rendered.
$templateVars = array('varOne' => $templateVariableOne, 'varTwo' => $templateVariableTwo);
return View::make('samples.create', $templateVars);
Assuming you're using Laravel 4, you don't need $this to make a View in a controller.
public function index()
{
return View::make('samples.create');
}
Also you got View and make the wrong way round.
Documentation here: http://laravel.com/docs/responses#views