How to call a view in voyager? - laravel

Im having issue to return a view in voyager.
This is inside my controller(App/Http/Controllers/TestController.php):
public function showGraph()
{
$users = DB::select('SELECT * FROM whmcs_clients_invoices');
return view('index', ["users"=>$users]);
}
From the above code, the index view is actually inside the voyager. (vendor/tcg/voyager/resources/views/index.blade.php)
This is inside my route(routes/web.php).
// WHMCS Client Paths
Route::get('/admin', 'TestController#showGraph');
The issue now is "View [index] not found."
Can i know how to put the path correctly so that the function can work?

Related

How to use parameter from function to create an URL? Laravel Routing

I'm sending an URL hashed and when i get it i have to show a view on Laravel, so i have those functions on the controller and also some routes:
This are my routes:
Route::post('/sendLink', 'Payment\PaymentController#getPaymentLink');
Route::get('/payment?hash={link}', 'Payment\PaymentController#show');
And this are the functions i have on my controller:
public function getPaymentLink (Request $request){
$budgetId = $request['url.com/payment/payment?hash'];
$link = Crypt::decryptString($budgetId);
Log::debug($link);
//here to the show view i wanna send the link with the id hashed, thats why i dont call show($link)
$view = $this->show($budgetId);
}
public function show($link) {
$config = [
'base_uri' => config('payment.base_uri'), ];
$client = new Client($config);
$banking_entity = $client->get('url')->getBody()->getContents();
$array = json_decode($banking_entity, true);
return view('payment.payment-data')->with('banking_entity', $array);
}
And this is getting a "Page not found" message error.
What i want to to is that when i the client clicks on the link i send him that has this format "url.com/payment/payment?hash=fjadshkfjahsdkfhasdkjha", trigger the getPaymentLink function so i can get de decrypt from that hash and also show him the view .
there is no need to ?hash={link} in get route
it's query params and it will received with $request
like:
$request->hash
// or
$request->get('hash')
You need to define route like this:
Route::get('/payment/{hash}', 'Payment\PaymentController#show');
You can now simply use it in your Controller method like below:
<?php
public function getPaymentLink (Request $request,$hash){
$budgetId = $hash;
// further code goes here
}

Laravel Meaning of Load View function

I want to know what is the function of loadView in Laravel.
Because I have a hard time viewing my view_path.
public function loadView($view_path, $params) {
$view = View::make($view_path, $params);
$contents = $view->render();
return $contents;
}
The view path is the path to the view starting from the folder resources/views/ and without the .blade.php extension.
For example if you want to load the view /var/www/html/myProject/resources/views/front/welcome.blade.php then the view path is "front/welcome".
You should probably use "view($view_path, $params)" to load your views at the end of your controllers.
As in :
return view("front/welcome", $params);
Where did you find this loadView function ?

not working #extends() use query in laravel

i try to display data with id, but problem is when just:
public function category()
{
return view('font.category.category');
}
#extends() blade is working. I try to query use this:
function public function category($id)
{
$pCategoryById = Menu::where('id', $id)->get();
return view('font.category.category', 'pCategoryById'=>$pCategoryById]);
}
#extends() blade is not working how to solve it? url is {{url('/category/'.$result->id)}} web is: Route::get("/category/{id}",'fontController#category');.
in url
{{url('/category',$result->id)}}
in controller
$pCategoryById=Menu::find($id);
return view('font.category.category',compact('pCategoryById'));
In the url,
{{url('/category',$result->id)}}
Or you can use as like,
{{url('/')}}/{{$result->id}}
In the Controller,
$pCategoryById=Menu::where('id',$id)->get();
return view('font.category.category',compact($pCategoryById));
If #extends() is not working, then you have to check the right path which is extended.

How to access Model from Views in CodeIgniter

How to access Model from Views in Codeigniter.
I have a Model with a function, i need to call this function from view
Please Read the CI documentation First:
If You are using a MVC Structured Framework then you should be following the way it works.
You Need the Controller:
public function your_controller_function(){
// To load model
$this->load->model ('your_model');
//To Call model function form controller
$data = $this->your_model->model_function($ex_data);
//TO Send data to view
$this->load->view('your_view',['data'=>$data]);
}
Inside your model:
public function model_function($ex_data){
// Your Querys
// user return to send you query result to the controller anything
// Sample Example of query and return
$query = $this->db->select('*')
->where('your_column',$data['column_name'])
->get('your_table');
$your_result = $query->row_array();
if($this->db->affected_rows() > 0){
return your_result;
} else {
return FALSE;
}
}
Inside your view you can write :
<?php
$this->load->model('your_model');
$this->your_model->some_function();
?>
For example in User_controller load User Model $this->load->model('Users_model');
Then User View page $viewpage = this->Users_model->somefunction($id);

Laravel 5.4 Undefined Variable from controller to view

I recently got started with Laravel 5.4, I'm familiar with 5.3. I'm trying to pass a variable from my controller to the view and keep getting an "Undefined variable $savedStores".
public function index()
{
//
$stores = Store::where('id as user_id')->get();
return view('home')->with('savedStores', $store);
}
That is my controller code.
In my view, I have
#if(count($savedStores)>0)
#foreach($savesStores as $savedStore)
<p>{{$savedStore -> name}}</p>
#endforeach
#endif
return view('home',['savedStores'=>$stores]);
spelling mistake chane $store to $stores
Just change your code:
from:
$stores = Store::where('id as user_id')->get();
to:
$stores = Store::where('id',$some_id_value)->get();
Or you can get all store records by:
$stores = Store::all();
You are passing the variable to view in correct manner.
More details check here:
https://laravel.com/docs/5.4/views
Actually with method used for session data.
You can pass variables to view.
return view('home',['savedStores'=>$stores]);
or
return view('home',compact('stores')); // as store variable.
Try this one,
public function index()
{
$stores = Store::select('*','id as user_id')->get();
dd($stores);//see query result, if you get correct result here, just remove this line
return view('home')->with('savedStores', $stores );
}

Resources