Laraveldaily example without visible output of database query - laravel

Learning CRUD by example from
https://laraveldaily.com/post/laravel-8-vue-3-crud-composition-api
I got stuck in the middle of the lesson (before the step “Add Button to Delete Company”).
Everything seems to work, but the result of the query is not visible. Countercheck in postman shows, that the record is found - but not displayed in my dashboard. Telescope doesn’t help anything here.
Then I started tracing, not really knowing and searching for the execution sequence.
To my understanding the result should be placed in <router-view /> of the file dashboard.blade.php (I added the two h2-Tags, which are displayed):
> <x-app-layout>
> <x-slot name="header">
> <h2 class="font-semibold text-xl text-gray-800 leading-tight">
> {{ __('Dashboard') }}
> </h2>
> </x-slot>
> <div class="py-12">
> <div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
> <div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
> <div class="p-6 text-gray-900">
> <h2>RouterView Start</h2>
> <router-view />
> <h2>RouterView End</h2>
> </div>
> </div>
> </div>
> </div>
> </x-app-layout>
For tracing I entered some info("….") into web.php and auth.php and got:
[2023-02-06 14:35:44] local.INFO: api.php url=http://127.0.0.1:8000/dashboard
[2023-02-06 14:35:44] local.INFO: web.php: middleware
[2023-02-06 14:35:44] local.INFO: auth.php ENTRY
[2023-02-06 14:35:44] local.INFO: auth.php: ---> midw: guest
[2023-02-06 14:35:44] local.INFO: auth.php: ---> midw: auth
[2023-02-06 14:35:44] local.INFO: web.php: dashbord
Furthermore in web.php I do not understand
Route::view('/{any}', 'dashboard')
->middleware(['auth'])
->where('any', '.*');
I’d like to know, if this is addressed at all by entering something like info(“”), but I don’t know how to extend the statement.
How can I enter more echo() or similar in class definitions? I tried to add the following in CompanyController.php:
public function __construct() {
echo("CompanyController Start");
}
but I don’t get an echo.
Now I’m lost in space.

Related

Cannot find parent element in DOM tree containing attribute: [wire:id]

I am laravel developer and developing a real time chat room using liveware , i am trying to open chat when i click to user but unfortunatly i am getting error https://flareapp.io/share/OmVDe437#F47 please help me how can resolved that ? thank u.
I am also getting error in console.
app\Http\Livewire\Messaging.php
public $selectedConservation;
public function mount(){
$this->selectedConservation = Conservation::query()
->where('sender_id',Auth::user()->id)
->orwhere('reciever_id',Auth::user()->id)
->first();
}
public function viewMessages($conservationsId){
$this->selectedConservation =
Conservation::findorFail($conservationsId);
}
public function render()
{
$conservation = Conservation::query()
->where('sender_id',Auth::user()->id)
->orwhere('reciever_id',Auth::user()->id)
->get();
return view('livewire.messaging',[
'conservation' => $conservation,
]);
}
resources\views\livewire\messaging.blade.php
#foreach ($conservation as $conservations)
<a href="#" wire:click.prevent="viewMessages({{ $conservations->id}} )">
<div class="user-card rounded bg-dark bg-opacity-10 mb-1">
<div class="mx-2">
<div class="d-flex pt-3">
<img class="rounded-circle" width="48px" height="48px" src="{{Config('wfh.file').$conservations->reciever->avator}}" alt="">
<div class="notification-text ms-3 w-100">
<span class="username fw-bold">{{$conservations->reciever->full_name}}</span>
<span class="float-end small"></span>
<p class="mt-1 text-muted">You: </p>
</div>
</div>
</div>
</div>
</a>
#endforeach
Check out the documentation on Dom Diffing Issues. It looks like you need to add a wire:key="{{ $conversations->id }}" attribute into your a tag so that Livewire can track changes to the list of conversations.

Laravel Breeze Vue - Link and page not rendering

I working on an app and using Laravel Breeze Vue for the first time. Just some quick background, Laravel Breeze provides some quick scaffolding for authentication. When a user logs in, they are presented with a simple dashboard page. I have added a new link to this page as per below.
app/resources/js/Layouts/Authenticated.vue
<!-- Navigation Links -->
<div class="hidden space-x-8 sm:-my-px sm:ml-10 sm:flex">
<BreezeNavLink :href="route('dashboard')" :active="route().current('dashboard')">
Dashboard
</BreezeNavLink>
<BreezeNavLink :href="route('client.index')" :active="route().current('client.index')">
Clients
</BreezeNavLink>
</div>
I have also created an Index.vue file at file path app/resources/js/Pages/Client/Index.vue. It looks like below:
<template>
<Head title="Clients" />
<BreezeAuthenticatedLayout>
<template #header>
<h2 class="font-semibold text-xl text-gray-800 leading-tight">
Clients
</h2>
</template>
<div class="py-12">
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
<div class="p-6 bg-white border-b border-gray-200">
You're logged in!
</div>
</div>
</div>
</div>
</BreezeAuthenticatedLayout>
</template>
<script>
import BreezeAuthenticatedLayout from '#/Layouts/Authenticated.vue'
import { Head } from '#inertiajs/inertia-vue3';
export default {
components: {
BreezeAuthenticatedLayout,
Head,
},
}
</script>
I am using a route resource in my web.php file as per below. I have confirmed that client.index is an existing route via php artisan route:list.
//client routing
Route::middleware(['auth', 'verified'])->group(function() {
Route::resource('client', ClientController::class);
});
I am facing two problems. The first problem is that the link will not render in my navigation links. The second issue is that the Index.vue page will not render as well. I have tried doing npm run dev, npm run watch and clearing caches. None of these have worked. Please provide me with some insight on how to address these issues.
This is closed. I'm using old hardware and it was taking time to pick up the changes. npm run dev performed as expected.

Laravel 8 Livewire component Undefined variable: header

I have created a Livewire component in Jetstream and I have set it as a full-page component in the web.php route page as follows:
use App\Http\Livewire\PostComponent;
...
Route::get('posts/',PostComponent::class)->name('posts');
The post-component.blade.php file has originally the following code:
<div>
<h1>If you look to others for fulfillment, you will never truly be fulfilled.</h1>
</div>
If I hit the URL .../posts I get the following error:
Undefined variable: header (View:
/home/vagrant/laravelapp/resources/views/layouts/app.blade.php)
So I have tried adding the slot in the post-component.blade.php file:
<x-app-layout>
<x-slot name="header">
<h2 class="font-semibold text-xl text-gray-800 leading-tight">
{{ __('Dashboard') }}
</h2>
</x-slot>
<div>
<h1>If you look to others for fulfillment, you will never truly be fulfilled.</h1>
</div>
</x-app-layout>
Nevertheless, I get that same error.
What am I missing? How do I fix this?
I hope this is a Jetstream project. By default, livewire will use the app.blade.php as the layout. And the component will get rendered in the slot of the app.blade.php.
But since it's a Jetstream project, it has a slot for the header in the layout file.
<header class="bg-white shadow">
<div class="max-w-7xl mx-auto py-6 px-4 sm:px-6 lg:px-8">
{{ $header }}
</div>
</header>
So to resolve this error, there are two approaches.
give the header as the variable for the layout as below in your PostComponent.php
public function render()
{
return view('livewire.post-component')
->layout('layouts.app', ['header' => 'Post Compoent Page']);
}
Create your own layout and only have a slot. (imagine mylayout.blade.php)
<head>
#livewireStyles
</head>
<body>
{{ $slot }}
#livewireScripts
</body>
and use that layout when rendering the livewire component
public function render()
{
return view('livewire.post-component')->layout('layouts.mylayout');
}
There is a github issue regarding this topic (a closed one). But keep an eye on it. since Jetstream is in it's early stages.

Laravel Dusk - Check box not clicking

I'm developing a few browser tests using Laravel Dusk for my VueJs/Laravel Application.
I'm trying to "check" a checkbox but I'm having issues. I managed to wait for its parent element to be visible, but when I check the checkbox and assert value to see if it's true, I get an error.
My test file
$this->browse(function ($browser) {
$browser->visit(route('login'))
->assertPathIs('/login')
->type('email', $this->user->email)
->type('password', 'password')
->press(trans('auth.login'))
->assertPathIs('/dashboard')
->visit(route('settings.edit', $this->customer->uuid))
->assertPathIs('/settings/edit/'.$this->customer->uuid)
->whenAvailable('#switch-input-tfa', function() use ($browser) {
$browser->check('switch-input')
->pause(2000)
//This fails
->assertInputValue('switch-input', true);
}, 4)
->press(trans('nav-side.logout'))
->assertPathIs('/login');
});
Vue JS File
<div class="flex">
<h3 class="flex-grow text-lg leading-6 font-medium text-gray-900 mb-2">
{{ __('settings.2fa_global') }}
</h3>
<switch-input
dusk="switch-input-tfa"
v-model="form.tfa_enabled"
#change="settingChanged($event,'tfa_enabled')"
show-icons
:inactive-value="false"
:active-value="true"
inactive-icon="times"
active-icon="check"
:show-on-right="false"
/>
</div>
Switch-input component
<div>
<input name="switch-input"
class="w-full h-full absolute inset-0 opacity-0"
type="checkbox"
#change="handleChange"
ref="input"
v-bind="$attrs"
:class="[$attrs.disabled ? '' : 'cursor-pointer']"
>
</div>
The error message
Expected value [1] for the [switch-input] input does not equal the actual value [on].
Failed asserting that 'on' matches expected true.
I also tried with the "uncheck" function ,but I still get the same error that actual value is ON

Laravel returns 404 error when passing a parameter

Hello when I send a data press a link to show another view laravel returns a 404 error, what am I failing?, I have created other crud and I have had no problems so far
Expansion -> index.blade.php:
<a href="{{url('/cards/'.$expansion->exp_id.'/vcards')}}"class="btn btn-primary form-control" >Go!</a>
URL:
http://localhost/CardSystem/cartas/1/vcards
Route:
Route::resource('cards', 'cardControllerr');
cardController:
public function vcards($id){
$data['cards']= DB::table('cards')
->join('expansion','expansion.exp_id','=','cards.exp_id')
->select('cards.card_id','cards.card_nom','expansion.exp_nom')
->where('cards.exp_id','=',$id)
->orderBy('cards.card_num')
->paginate(5);
return view('cards.vcards',$data);
vcards.blade.php:
#extends('layouts.app')
#section('content')
<div class="container">
#foreach($cards as $card)
<div class="form-group">
<h5 class="card-title">{{$card->card_nom}}</h5>
</div>
#endforeach
</div>
#endsection
I think you misunderstood routing, views etc.
For your controller to be hit, you will need to make the following route.
Route::get('cartas/{card}/vcards', 'cardControllerr#vcards')->name('cartas.vcards');
If you wanna link to this route use route().
route('cartas.vcards', ['card' => $card]);

Resources