Laravel Orchid - unable to retrieve values from URL - laravel

I have an Orchid screen for displaying reports and want to display by month and year.
http://url.com/main/report/2022/01
I have this in my platform routes
Route::screen('/main/report/{year}/{month}', DashboardReportScreen::class)
->name('platform.report');
How can I access year and month from within my screen file?
Inside my DashboardReportScreen, the query function looks like this:
public function query(): iterable
{
print_r($year);
// NULL RETURN
}
How can I access custom parameters in my URI from within my screen?

You need to pass the arguments to the "query" function in your screen file as it is here https://orchid.software/en/docs/quickstart-crud/

Related

How do I pass a value in my Route to the Controller to be used in the View in Laravel?

I have 2 entities called Match and Roster.
My Match routes are like this
http://localhost:8888/app/public/matches (index)
http://localhost:8888/app/public/matches/14 (show)
In order to view/create the teams for each specific match I added the routes for the match roster like this:
Route::get('/matches/'.'{id}'.'/roster/', [App\Http\Controllers\RosterController::class, 'index']);
Now I need that {id} i have in my URL to pass it to the Controller here:
public function index()
{
return view('roster.index');
}
I need that for a couple of things. First I need to do a search on the Roster table filtering by a column with that value, so I can display only the players that belong to that match.
Second, I need to pass it on to the view so I can use it on my store and update forms. I want to add or remove players from the roster from that same index view.
How can I do that?
#1 You can get the route parameter defined on ur routes via request()->route('parameter_name').
public function index()
{
// get {id} from the route (/matches/{id}/roster)
$id = request()->route('id');
}
#2 You can pass the data object via using return view(file_name, object)
public function index()
{
// get {id} from the route (/matches/{id}/roster)
$id = request()->route('id');
// query what u want to show
// dunno ur models specific things, so just simple example.
$rosters = Roster::where('match_id', '=', $id);
// return view & data
return view('roster.index', $rosters);
}
#3 It can be done not only index but also others (create, store, edit, update)
In addition, STRONGLY RECOMMEND learn Official Tutorial with simple example first.
Like a Blog, Board, etc..
You need to know essentials to build Laravel App.
Most of the time, I prefer named routes.
Route::get('{bundle}/edit', [BundleController::class, 'edit'])->name('bundle.edit');
In controller
public function edit(Bundle $bundle): Response
{
// do your magic here
}
You can call the route by,
route('bundle.edit', $bundle);

Laravel Nova Metric displaying data from other metric

I have a two Nova Trend metrics called ApiCallsPerHour and ApiCallsPerMinute, each with a simple calculate function:
ApiCallsPerHour
public function calculate(NovaRequest $request)
{
return $this->countByHours($request, ApiCall::class);
}
ApiCallsPerMinute
public function calculate(NovaRequest $request)
{
return $this->countByMinutes($request, ApiCall::class);
}
The problem is the ApiCallsByMinute trend displays always displays the trend by hours.
I have tested and both components are loaded correctly: if I change their ranges array they independently update from each other. But whatever I put in the calculate method in the ApiCallsPerMinute, it always displays the hourly trend, even if I put return 100;.
Only when I remove the ApiCallsPerHour trend from the dashboard, the ApiCallsPerMinute is displayed correctly.
Both components do not have a value returned in the cacheFor method.
It was clear I was missing something big... These components had the same uriKey 🤦‍♂️. Don't copy paste your components folks, use the php artisan nova:trend command!

how to load different data tables in different tabs?

i am using laravel data tables to generate different data table on different tabs. but it runs only query of first data table rendered to the page.i already have attached scope to data table to generate different results for different condition
i have attached ajax() method to the data table that are not displayed in the beginning of the page
controller file
public function index(UpcomingReservationDataTable $UpcomingReservationDataTable)
{
return $UpcomingReservationDataTable->render('admin.reservations.index');
}
public function getAllReservationTable(ReservationDataTable $ReservationDataTable){
return $ReservationDataTable->render('admin.reservations.index');
}
public function getPastReservationDataTable(PastReservationDataTable $PastReservationDataTable){
return $PastReservationDataTable->addScope(new PastReservationScope)->render('admin.reservations.index');
}
pastreservationdatatable query
public function query(Reservation $model)
{
return $model->newQuery()->where('pickup_date','<',date('Y-m-d'))->orderBy('id','desc')->with('customer','package','vehicle');
}
You can show first table in load tab and next change it by ajax.
You must write a function in javascript. This function should take a value. This value contains your query information. When this is clicked on any tab, this function must be executed with that value. The function of this function is to send information to the server, receive and display. Did you do these things?
The next issue is when the Ajax data is sent, if the server path is wrong, you will encounter an error. To view errors on your browser, press the combination keys CTR + Shift + i and in the menu at the top of the window, select the console to display the errors.

how to handle dynamic url in laravel

i have a page called "jobs" in my application where all the jobs will be shown.
And i have search job input field on same page
where user search a job using input field it will redirect him to "jobs?keyword=abc"
And i also have a jobs filter section where user can filter a jobs by "location, contract_types".
i have created form by some javascript where user fills some fields that field only get submited by form.
i.e
if user searches a job by keyword then url will be like "jobs?keyword=abc".
if user filter jobs by location then url be like "jobs?location=abc".
if user filter jobs by contract types then url be like "jobs?contract_type=abc".
if user filter jobs by keyword and contract types then url be like "jobs?keyword=abc&contract_type=abc".
every time user submit a form url gets changing.
so my question is how to handle dynamic url on routes
currently i have this in my route
Route::get('jobs', 'todocontroller#jobs');
And my controller todocontroller.php
public function jobs()
{
//some code here
}
thanks in advance any help will be appreciated.
You can retrieve all parameters sent using request()->all();
this should go within your jobs function in the controller.
That is what Request do
public function jobs(Request $request)
{
$request->all(); // this is where all the query string, body or others param contains in it..
}
Example
if user searches a job by keyword then url will be like "jobs?keyword=abc".
then request->keyword return abc
if user filter jobs by keyword and contract types then url be like "jobs?keyword=abc&contract_type=abc".
then request->keyword return abc, request-> contract_type return abc
using path
/url/location/{param}
in controller
public function jobs(Request $request, $param)
{
$request->all(); // this is where all the query string, body or others param contains in it..
echo $param; //display param
}

How to get pretty URL in Codeigniter?

I have a product controller (Codeigniter) where I load 40 categories in my index function. When I click on a category, I want to load all item of that particular category. To do that, I can easily write a function to load all that items.
Function load_item($categoryId’)
{
// in short
…… where categoryId = ‘$categoryId’
// then load it to view
}
Then I have URL like /product/load_item. But I want URL like /product/laptop or /product/desktop (/product/category_name). So, it's not possible to write 40s function for every category and also its not optimal solution. I don’t want to change anything in index function. Have you any idea please???
You have to setup the routes for the url's so under your config folder go to routes and then create a route like so
$route['product/(:any)'] = 'catalog/product_lookup';
You can find all relevant information in the Codeiginter User Guide
Method 01
In routes.php
$route['category/(:any)'] = 'category/load_item';
Output - www.example.com/category/(value/number-of-category)
Method 02
In View URL passing method(Means <a>)
Click me
so in controller
Function item($catgoryName, $categoryId)
{
// in short
where categoryId = '$categoryId';
// then load it to view
}
Output - www.example.com/category/item/laptops/1

Resources