Appearance
How to create a temp/test route
Sometimes we need to create a temp route on our local env to test something.
A route can return simple view response (usually with HTML code), json response (json data + some special header(s)), redirect response and some other special cases.
JSON response
At the top of src/routes/web.php please add the following code:
php
Route::get('testing-of-simple-json-response', function () {
return response()->json(['message' => 'Your custom message']);
});You can access this route by '/testing-of-simple-json-response' URL.
View response
This is an example how to create a route that returns basic HTML page with 3 different Member cards
Simple view
If your route only needs to return a view, you may use the Route::view method. This method provides a simple shortcut so that you do not have to define a full route or controller. The view method accepts a URI as its first argument and a view name as its second argument. In addition, you may provide an array of data to pass to the view as an optional third argument:
php
Route::view('/welcome', 'pages.welcome.index');
// or
Route::view('/welcome', 'pages.welcome.index', ['companyName' => 'IxDF']);View with variables/logic
Step 1: At the top of src/routes/web.php please add the following code:
php
Route::get('testing-member-cards', function () {
// 'withoutGlobalScopes' needed to include canceled members
$memberA = \App\Modules\Member\Models\Member::query()->withoutGlobalScopes()->find(11989);
$memberB = \App\Modules\Member\Models\Member::query()->withoutGlobalScopes()->find(19172);
$memberC = \App\Modules\Member\Models\Member::query()->withoutGlobalScopes()->find(20001);
// Get the evaluated view contents for the given view.
return view()->make('pages.test3memberCards', [
'memberA' => $memberA,
'memberB' => $memberB,
'memberC' => $memberC,
]);
});Step 2: Create a new view Blade file src/resources/views/test3memberCards.blade.php (this path corresponds to an alias 'pages.test3memberCards'):
blade
<x-layouts.app-minimal title="Test Page"
>
<x-content-container>
Your HTML
</x-content-container>
</x-layouts.app-minimal>You can access this route by '/testing-member-cards' URL.