I am trying to fetch data from my admin_homes table, here is what my controller looks like:
public function index()
{
$home = AdminHome::all();
return view('admin.home.index', compact('home'));
}
I use foreach ($home as $homes) in my blade view but when I run it, I get an error saying "$home is undefined". How to solve this?
Related
First I use pagination and I want to change to all in my Controller, but I got the error above.
This is what I tried :
$c = CarModel::all();
My code :
public function index()
{
//$c = CarModel::all(); //got error when use this
$c = CarModel::paginate(3);
return view('car.car',compact('c'));
}
I want to change to $c = CarModel::all(); but I got error.
Looks like you are using ->links() method in your "car.car" view, this method is only available when you use pagination
I am using symfony 4.2 framework in which there is PHP controller with multiple actions. I have set below values in packages\config.yaml.
myDir: '/abc'
I have below controller with 2 actions as defined below.
//this works
public function uploadTestAction(Request $r_request)
{
$myDir = $r_request->request->get("myDir");
}
//this doesn't work
public function loadTestAction(Request $r_request)
{
$myDir = $r_request->request->get("myDir");
//$myDir = $r_request->query->get("myDir"); //this is also not working
}
Issue here is I am able to get the value in uploadTestAction but value is coming as null in uploadTestAction. I have tried using query as well but still not getting the correct value. Both request types are GET. What I am missing here or how can trace it ?
you should define it as parameter:
https://symfony.com/doc/current/service_container/parameters.html
final class XyController extends SymfonyController {
public function registerAction() {
$dir = $this->container->getParameter('dir');
}
}
I have this problem in my routes where in I get this error tying to get property of non-object view (show.blade.php) on clicking a link to view/redirect allstats.blade.php. It is very weird because I am not returning my routes to show.blade.php but to allstats.blade.php. I was wondering if I am doing something wrong with the routes. This is very tricky, I don't know what's causing this error.
#Controller:
EmployeeController.php
public function postdisplaySummaryReport()
{
$employeesquery = Employee::paginate(10);
return View::make('employees.allstats')
->with('employeequerytoallstat', $employeesquery);
}
#Routes:
routes.php
Route::post('employees/sumarryReports','EmployeeController#postdisplaySummaryReport');
Route::resource('employees', 'EmployeeController');
#index.php(URL to the allstat.blade.php):
<span class="glyphicon glyphicon-folder-open"></span> {{trans('labels.payroll_reports.lbl_summary_report')}}
#ERROR:
Just change your function to this.
public function postdisplaySummaryReport()
{
$employeesquery = Employee::paginate(10);
return view('employees.allstats')
->with('employeequerytoallstat', $employeesquery);
}
also change your Route method to get instead of post if you want to display content.
Route::get('employees/sumarryReports','EmployeeController#postdisplaySummaryReport');
I'm trying to pass an array from a function to another function in laravel.
In my PageController.php, I have
public function show($code, $id){
//some code
if(isset($search))
dd($search);
}
and another function
public function search($code, $id){
//some queries
$result = DB::table('abd')->get();
return Redirect::action('PageController#show, ['search'=>$search]);
}
But this returns me an error like this: ErrorException (E_UNKNOWN)
Array to string conversion
I'm using laravel.
You could maybe get it to work with passing by the URL by serialization, but I'd rather store it in a session variable. The session class has this nice method called flash which will keep the variable for the next request and then automatically remove it.
Also, and that's just a guess, you probably need to use the index action for that, since show needs the id of a specific resource.
public function search($code, $id){
//some queries
$result = DB::table('abd')->get();
Session::flash('search', $search); // or rather $result?
return Redirect::action('PageController#index');
}
public function index($code){
//some code
if(Session::has('search')){
$search = Session::get('search');
dd($search);
}
}
Hi i am trying to call a model from view but i am getting error as.
A PHP Error was encountered Severity: Notice Message: Undefined property:
CI_Loader::$Stopsmap_Model Filename: stopsmap/index.php Line Number: 59
i tryed this below code in view.But no luck
foreach ($routes as $route_details):
//calling model
//$trip_max_min_sequence_details = $this->load->Stopsmap_Model->fullTripdetails($trips->trip_id); i tried this also but same error
//$this->load->model('Stopsmap_Model');
//$data = $this->stopsmap_model->fullTripdetails($route_details->route_id); i tried this also but same error
$this->load->model('fixedtransit_model/Stopsmap_Model');
$get_route_related_trips = $this->Stopsmap_Model->getRoutetrips($route_details->route_id);
if(count($get_route_related_trips)>=1):
echo '1 stop';
endif;
endforeach;
thanks in advance for the help
In your controller , you can have like this:
function routes(){
//call model
$this->load->model('fixedtransit_model/Stopsmap_Model');
$routes = $this->topsmap_model->get_routes();
foreach ($routes as $route_details){
$get_route_related_trips[] = $this->Stopsmap_Model->getRoutetrips($route_details->route_id);
}
$data['related_routes'] = $get_route_related_trips;
//load view and pass data
$this->load->view('myview' , $data);
}
and in your view:
<?php foreach($related_routes){
//do something
}
?>
on my end
i have created a model named accountmodel in applications/models dir
and load in view like (would be best if you load model in your controller):-
$this->load->model('AccountModel','Account');
//AccountModel (model class name)
//Account (object) you can further use this model using object
for more info :- http://ellislab.com/codeigniter/user-guide/general/models.html