Laravel Dusk VueJS SPA router-view injected components - laravel

I use <router-view> to inject components based on the route. I want to make vue-assertions in Laravel Dusk now.
<router-view :key="$route.fullPath" :dusk="$route.name"></router-view>
But when I do ->assertVue('field', 'value', '#indexOrder') on my order index route, I get this error:
Facebook\WebDriver\Exception\UnexpectedJavascriptException: javascript error: Cannot read property '__vue__' of null
Of course, I made sure that the route's name is indexOrder and is correctly put in the dusk-attribute of the router-view component. How can I fix that?

While this is not exactly an answer, it can help move you in the right direction.
When you run the following command in your browser console on the route you're testing, you'll see a $children variable.
document.querySelector('body [dusk="YOUR_ROUTE_NAME"]').__vue__;
The above command is what Dusk executes in its MakesAssertions trait under the vueAttribute method. This $children variable holds all of your components loaded by the router, so you'll have to create some new methods and assertions to support vue-router in Dusk.

Related

How to stop the GET method is not supported for this route from showing?

I have a working Laravel project with loads of different routes.
I'm currently testing it and one of my tests was to check if a user were to use a delete or post route from the URL. I didn't know what the application would do honestly and it outputted the typical:
The GET method is not supported for this route. Supported methods: DELETE
which I have seen a million times. Is there a way to stop this error from coming up and instead output an error screen or simply redirect to a different view?
The error message:
The GET method is not supported for this route. Supported methods: DELETE.
should only appear when your Laravel site has APP_DEBUG set to true (in the .env file).
When APP_DEBUG is set to false as it should always be in on a live site, then the user will be shown a 404 error page instead.
You can easily test this by adding the following code to your routes file:
Route::delete('test', function() {
return 'You should never see this text when viewing url via a GET request';
});
May be u didn't noticed but ur form tag method attribute and route definition is different

Laravel Jetstream with Intertia not returning User

I have installed Jetstream with Intertia. I register a user, then try to login, and the console gives me the following error:
[Vue warn]: Error in render: "TypeError: _vm.$page.user is null"
When I look at the response from the controller, indeed it does not include a user.
Where is the user attached? Presumably in some middleware. But which?
Here are two web routes that exhibit the problem. Note the differences in middleware.
Route::middleware(['auth'])->get('/dashboard', function () {
return Inertia\Inertia::render('Dashboard');
})->name('dashboard');
Route::get('/map', [MapController::class, 'show'])->name('map');
I have also tried the middleware auth:sanctum and verified.
You are correct about the user. It's attached in the ShareInertiaData middleware provided by Jestream.
Assuming you updated inertia to some newer version, the reason why your user is null has probably something to do with the fact that since inertia-vue#v0.3.0 the $page returns a full page object, instead of just the page props - so in your case, instead of $page.user, you'd have to go with $page.props.user.
https://github.com/inertiajs/inertia/releases/tag/inertia-vue%40v0.3.0

Exclude conditional routes in Laravel

I'm building and application in Laravel and Vuejs where I'm having Laravel routes as below:
Route::get('/admin/{view?}', 'HomeController#admin')->where('view', '(.*)')->name('admin');
Route::get('/{view?}', 'HomeController#home')->where('view', '(.*)')->where('view', '!=', 'admin')->name('home');
I'm using Vue-router so I'm having routing in vuejs, and I'm using history mode. The problem is when I try to call /admin it generally calls HomeController#home method. even if I go deeper like /admin/dashboard it is calling the same home method. I want if admin prefix is being called then it should call HomeController#admin method.
its all okay for me please check this
Route::get('/admin/{view?}', function (){
dd('okay');
})->where('view', '(.*)')->name('admin');
Route::get('/{view?}', function(){
dd('okay1');
})->where('view', '(.*)')->name('home');
So try this
Route::get('/admin/{view?}', 'HomeController#admin')->where('view', '(.*)')->name('admin');
Route::get('/{view?}', 'HomeController#home')->where('view', '(.*)')->name('home');

i want to open a new window with passing id of students shows error in new window

I am successfully loading a page in a new window using target="_blank",but the problem is the new window is loading with an error NotFoundException, when i try to pass id from the current window to new window
{{$stud->name}}
Route::get('search/display/{$id}','studcontroller#searchstud');
.....
NotFoundException is occurred for the routes not declared.
Check if you have created a route in routes.php.
Also verify the method to be GET.
If you have cached your routes earlier, try refreshing the route cache by using the command php artisan route:cache.
NOTE: This route cache command will work only if you are not using any
closure route.
One more thing you can do to get proper link is, use Url::to() method supported by Laravel Illuminate.
You're not closing the href attribute value. So, add ":
{{$stud->name}}
Like #Alexey mentioned you where missing quotes, but you will also have to send the id parameter
{{$stud->name}}

Dynamic redirect in package route

I have defined a route action with some business logic, inside an internally developed package. Depending on the result in this action, the app want to redirect the user to some dynamic route (Redirect::route('admin.index', [$app->id]) e.g).
How would I do this?
Any solution I come up with doesn't work because of the way Laravel handles routes.
Right now I have copied the route to the app routes.php, and extracted the business logic to a method inside the package. But this is not optimal, as I'd like to also keep the route inside the package.
Laravel has some documentation on Package Configuration that should work for you.
In your package's src/config/config.php:
<?php
return array(
'route_admin_index' => 'admin.index',
);
Change your package's code to:
Redirect::route(Config::get('your_package_name::route_admin_index'), [$app->id]);
Now when installed on different environments, you can do:
php artisan config:publish your_vendor_name/your_package_name
Which will publish your package's configuration file to:
app/config/packages/your_vendor_name/your_package_name
Where then you can change the route_admin_index at will.
If php artisan config:publish was not called. Your route will default back to what you have in your package's config file.

Resources