What is the wrong with my makeView? - php

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

Related

Laravel 8 return blank page

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');
}

Get data from Controller in Laravel 7

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.

call model relation function in controller laravel

In my Model I have the function
App\Akte.php
public function lvs() {
return $this->hasMany('App\lvs', 'lv_id');
}
In my Controller I call
public function index()
{
$aktes = \App\Akte::all();
return view('admin.akte.index', ['aktes' => $aktes]);
}
And i´d like to extend my collection $aktes with the lvs table. Can somebody explain how to do this?
So my result should be a collection in which every single element of "Akte" has its Many collections of lvs in it..
If you also want the relationship loaded, just use:
$aktes = \App\Akte::with('lvs')->get();
See that. May be usefull for your needs.
https://laravel.com/docs/5.7/eloquent-relationships
public function index()
{
$aktes = \App\Akte::->all()->where('lvl', 2);
return view('admin.akte.index', ['aktes' => $aktes]);
}
somthing like this ...

how do I pass on large datasets across different route requests - Laravel

Question might be unclear. here's the explanation. Let's say I've:
Route file:
Route::get('testing', 'someController#functionOne');
Route::get('testingtwo', 'someController#functiontwo');
Controller file:
public function functionOne() {
$this->data = generateReallyBigArray();
return redirect('testingtwo');
}
public function funtionTwo() {
// Here $this->data is lost. obviously 'coz this controller file got reinstantiated for #functionTwo
return view('someview', ['data' => $this->data]);
}
$this->data is lost the moment testingtwo is hit. How do I pass this data across different route requests? Or if there're other ways of doing it.
I was thinking of doing this:
public function functionOne() {
$this->data = 'somedata';
return $this->functionTwo();
}
public function funtionTwo() {
// Here $this->data is lost. obviously 'coz this controller file got reinstantiated for #functionTwo
// even this doesn't work. Exception: Method get does not exist
return Route::get('testingtwo', function() {
return view('someview', ['data' => $this->data]);
});
}
use with() to send data through session -
public function functionOne() {
$this->data = 'somedata';
return redirect('testingtwo')->with('data', $this->data);
}
Or you could flash() the data for using on next request.
$request->session()->flash('data', $this->data);
the best way for that is
traits
trait Data{
public function getData() {
// .....
}
}
and in your controllers write
use Data;
you can use traits over controllers
or
You can access your controller method like this:
app('App\Http\Controllers\controllerName')->getDataFunction();
This will work, but it's bad in terms of code organisation (remember to use the right namespace for your ControllerName)

Error: Method with does not exist laravel

I keep on getting this error method with does not exist and I have no idea how to fix it. I saw people who posted similar question like this and it usually the fault of all() but I am not using it. Can anyone help?
controller:
public function getPerson(){
return view('show');
}
public function getInfo($id) {
$user_info1 = user_info1::where('user_id',$id)->get();
$data['data'] = DB::table('personal_infos')::with('userinfo1s')->get()->sortByDesc('upload_time'); //error come from this line
return view('test', compact('user_info1','data'));
}
the function sortByDesc must before the function get();
sortByDesc is in collection laravel.. use orderby instead
$data['data'] = PersonalInfos::with('userinfo1s')->orderby('upload_time')->get();

Categories