user _id doesn't have a default value laravel - laravel

user_id doesn't have a default value that's is the error I'm getting when I clicked on the clone button and also user_id is fillable livewire movie show components
public function clone(Movie $movie)
{
$cloneMovie = $movie->replicate();
$cloneMovie->cloned_movie_id = $movie->id;
$cloneMovie->save();
}
livewire movie show blade view
<div>
<div class="">
<div class="p-1 bg-white rounded-md">
<div class="flex justify-between p-2 mb-2 text-white bg-gray-400 rounded-md">
<h3 class="font-bold text-white text-md">{{ $movie->title }}</h3>
<span class="text-xs">100 views</span>
</div>
<img src="{{ asset('/assets/images/blog/img-1.jpg') }}" alt="" class="w-auto rounded-md">
<p class="p-2">{{ $movie->body }}</p>
<button wire:click="clone({{ $movie->id }})">clone</button>
</div>
</div>
</div>

$cloneMovie->push();
Is what you’re looking for.

Related

Livewire component vanish after emitting event

I made chat app using livewire, and i want to emit an event where in that event emitting antohter event to another component, but when i emit the event the component it self vanish from view, and i dont know why here is my code
<div class="flex flex-row py-2 px-2 items-center border-b-2 cursor-pointer hover:bg-gray-100" wire:click="$emit('chatUserSelected',{{$conversation}})">
and the event in chatlist component
protected $listeners = ['chatUserSelected'];
public $conversations;
public $selectedConversation;
public function chatUserSelected(Conversation $conversation)
{
$this->selectedConversation = $conversation;
$receiverInstance = KontakModel::find($conversation->kontak_id);
$this->emitTo('chat.chat-box','loadConversation',$this->selectedConversation,$receiverInstance);
$this->emitTo('chat.send-message','updateSendMessage',$this->selectedConversation,$receiverInstance);
}
public function mount()
{
$this->auth_id = auth()->id();
$this->conversations = Conversation::orderBy('last_time_message','DESC')->where('solved_at',NULL)->get();
// dd($this->conversations);
}
public function render()
{
return view('livewire.chat.chat-list', );
}
here is my view before emitting event
and after emitting event
the chatlist somehow disappear
for additional this is code for my main view
<div class="flex flex-row justify-between bg-white h-screen" x-data="chatApp">
#livewire('chat.chat-list')
#livewire('admin.side-bar')
<!-- message -->
#livewire('chat.chat-box')
<!-- end message -->
</div>
chat.chat-list.blade.php
<div class="overflow-y-auto">
#forelse ($conversations as $conversation)
<div class="flex flex-row py-2 px-2 items-center border-b-2 cursor-pointer hover:bg-gray-100" wire:key="{{$conversation->id}}" wire:click="$emit('chatUserSelected',{{$conversation}})">
<div class="w-1/4">
<img
src="https://source.unsplash.com/otT2199XwI8/600x600"
class="object-cover h-12 w-12 rounded-full"
alt=""
/>
</div>
<div class="w-full">
<div class="text-lg font-semibold">{{ $conversation->kontak->name }}</div>
<span class="text-gray-500">{{$conversation->messages->sortBy('created_at')->last()->body}}</span>
</div>
<div class="w-2/12">
#php
$unread = $conversation->messages->where('status', NULL)->where('category','receive')->count()
#endphp
#if ($unread > 0)
<div class="text-sm text-center font-light rounded-full bg-red-600 text-white min-w-5 h-5">{{$unread}}</div>
#endif
<span class="text-xs">{{$conversation->messages->sortBy('created_at')->last()->created_at->shortAbsoluteDiffForHumans()}}</span>
</div>
</div>
#empty
<div class="flex flex-row py-2 px-2 items-center border-b-2 text-2xl text-center">
<div class="text-center m-auto">
No Conversation
</div>
</div>
#endforelse
</div>

Laravel Livewire multiple components not started asyncronously

I have 4 livewire components, rendered in dashboard as:
#livewire('profits.stats')
#livewire('costs.stats')
#livewire('leads.stats')
#livewire('sales.stats')
However, when page loads they run one after another instead of asyncronously. I put a sleep(3) to test, and each starts after the previous ones 3 second delay. How to get them to all start same time?
toggleShowData below has the sleep method, and sets showData=true. I saw this in a tutorial for now to have a loading for individual components
I don't think its relevant, but here is my template:
<div wire:init="toggleShowData">
<div wire:loading.delay class="align-items-center">
<div class="flex items-center justify-center ">
<div class="w-40 h-40 border-t-4 border-b-4 border-brand-500 rounded-full animate-spin"></div>
</div>
</div>
<div class="flex-auto p-4 bg-brand-300 rounded" wire:loading.remove>
<div class="flex flex-wrap">
<div class="relative w-full pr-4 max-w-full flex-grow flex-1">
<h5 class="text-gray-100 uppercase font-bold text-xs"> Costs</h5>
<span class="font-semibold text-xl text-gray-300">$34,100</span>
</div>
<div class="relative w-auto pl-4 flex-initial">
<div
class="text-white p-3 text-center inline-flex items-center justify-center w-12 h-12 shadow-lg rounded-full bg-red-500">
<i class="fas fa-chart-bar"></i>
</div>
</div>
</div>
<p class="text-sm text-gray-100 mt-4">
<span class="text-emerald-500 mr-2"><i class="fas fa-arrow-up"></i> 2,99% </span>
<span class="whitespace-nowrap"> Since last month </span></p>
</div>
</div>
The first render of the livewire page happens inside the PHP process in the backend.
Blade sees that you are requesting a livewire component and replaces this with the result of your parse() method from your component.
This indeed happens in sync, once the page is rendered the components can render itself async

Unable to call component method. Public method [storeLike] not found on component:

Hello I'm trying to fix an issue I'm having with my livewire like component. I have a post-show component and a like component. In the post-show blade I have:
<livewire:like :post="$post"/>
And inside this component:
<div class="w-full flex justify-center mt-3 text-white">
<x-jet-action-message class="text-white" on="post-liked">
{{ __('Liked') }} {{$post->title}}
</x-jet-action-message>
<x-jet-action-message class="text-white" on="post-unliked">
{{ __('Unliked') }} {{$post->title}}
</x-jet-action-message>
</div>
#if (!$post->likedBy(auth()->user()))
<div class="mb-7 mt-4 text-center">
<div class="block items-center">
<x-jet-button wire:click.prevent="storeLike" class="bg-blue-500 px-8 py-3 ">Like</x-jet-button>
</div>
</div>
#else
<div class="mb-7 mt-4 text-center">
<div class="block items-center">
<x-jet-button wire:click.prevent="destroyLike" class="bg-red-500 px-8 py-3" >Unlike</x-jet-button>
</div>
</div>
#endif
Now why does it say that the method is not found when it's there?

Laravel issue in room booking

Hi all I have some issue with my code ..
The idea is that I have multi room's which I retrieve from database every room have multi booking date my idea is to show when open room page all page if the room have current reservation mark it red or future reservation marked blue I can't know how to make this happen my room.blade is:
#section('content')
<div class="row text-right ">
#foreach ($room_typ as $a )
<div class="col-12 col-lg-2">
<div class="card radius-15">
<div class="card-body text-center radius-15">
<h4 title="{{ $a->r_det }}" class="mb-0 font-weight-bold mt-0 text-white">{{ $a->r_name }}
</h4>-<h6>{{ $a->f_name }}</h6>
<span class="mt-1 mb-1 acupp"></span>
<i class="bx bx-plus"></i>
<i class="fadeIn animated bx bx-trash-alt mr-md-3"></i>
<i class="bx bx-info-square mr-md-3"></i>
{{ $rr }} // should show the count for reservation with room number
</div>
</div>
</div>
#endforeach
</div>
#endsection
the controller is :
public function allrom()
{
$room_typ = addroom::all();
foreach ($room_typ as $dd) {
$rom = $dd->r_name;
$rr = res_c::where('rno', '=', $rom)->get();
}
echo view('room', compact('room_typ', 'rr'));
}
Try this please change the checkin and checkout fields with the one in your database let me know if it work
#section('content')
<div class="row text-right ">
#foreach ($room_typ as $a )
<div class="col-12 col-lg-2">
<div class="card radius-15" style="{{ date("Y-m-d") >= date("Y-m-d",strtotime($a->r_date_checkin)) && date("Y-m-d") < date("Y-m-d",strtotime($a->r_date_checkout)) ? "background-color:red" : ( date("Y-m-d") > date("Y-m-d",strtotime($a->r_date_checkin) ) ) ? "background-color:blue" : "" }}">
<div class="card-body text-center radius-15">
<h4 title="{{ $a->r_det }}" class="mb-0 font-weight-bold mt-0 text-white">{{ $a->r_name }}
</h4>-<h6>{{ $a->f_name }}</h6>
<span class="mt-1 mb-1 acupp"></span>
<i class="bx bx-plus"></i>
<i class="fadeIn animated bx bx-trash-alt mr-md-3"></i>
<i class="bx bx-info-square mr-md-3"></i>
{{ $rr }} // should show the count for reservation with room number
</div>
</div>
</div>
#endforeach
</div>

How to highlight the class from an object prop in vue.js with laravel

I need help or suggestion in highlighting / toggling a class and displaying data I'm just using blade/server-side in passing props, so from this in blade
<chat-app :respondent="{{ $user[0]->respondent }}" :user="{{ auth()->user() }}"></chat-app>```
then inside the ChatApp.vue file
<message-inbox :contact="respondent" :messages="messages"></message-inbox>
the contact prop there contains the user object that we'll send the chat to... including his id and display name and other basic details..
now I want to fetch all the messages but also highlighting that specific respondent's message.
<li class="bg-blue flex flex-no-wrap items-center text-black cursor-pointer p-3">
<img class="flex justify-center items-center flex-no-shrink w-12 h-12 bg-grey rounded-full font-semibold text-xl text-white mr-3" :src="userAvatar" alt="">
<div class="flex-1 min-w-0">
<div class="flex justify-between mb-1">
<h2 class="font-semibold text-sm">
<i class="fas fa-users fa-fw"></i> {{ conversation.respondent }}
</h2>
<span class="text-sm">
<i class="fas fa-check fa-fw"></i>
10:00
</span>
</div>
<div class="text-sm truncate">
<span>
Some latest messages from this conversation.
</span>
</div>
</div>
</li>
props : {
contact : {
type : Object,
default : null
},
messages : {
type : Array,
default : []
},
}
I think you should do the following to highlight the mentioned respondent.
Change your li tag as below code:
<li class="bg-blue flex flex-no-wrap items-center text-black cursor-pointer p-3" :class="{'highlight': conversation.respondent == respondent}">
<img class="flex justify-center items-center flex-no-shrink w-12 h-12 bg-grey rounded-full font-semibold text-xl text-white mr-3" :src="userAvatar" alt="">
<div class="flex-1 min-w-0">
<div class="flex justify-between mb-1">
<h2 class="font-semibold text-sm">
<i class="fas fa-users fa-fw"></i> {{ conversation.respondent }}
</h2>
<span class="text-sm">
<i class="fas fa-check fa-fw"></i>
10:00
</span>
</div>
<div class="text-sm truncate">
<span>
Some latest messages from this conversation.
</span>
</div>
</div>
</li>
Add highlight class in your CSS part as below:
.highlight {
color: yellow;
}

Resources