only return view from the render method . There you can switch view if you must, but you might like to think about the principle of single responsibility
Mar 31, 2022
3
Level 1
How can call two Different blade inside livewire Component class
hello i try to return view in another function in the same component i don't want use redirect , want use it like contoller one component for all method (create,edit) , i can do it or only should redirect create to creatComponent ?
<?php
namespace App\Http\Livewire;
use App\Models\Post;
use Illuminate\Support\Facades\File;
use Livewire\Component;
use Livewire\WithPagination;
class Posts extends Component
{
use WithPagination;
protected $paginationTheme = 'bootstrap';
public function render()
{
$posts = Post::with('user','category')->orderBy('id','desc')->paginate(5);
return view('livewire.posts',['posts' => $posts])
->extends('layouts.app')
->section('content');
} //END METHOD
public function create_post()
{
return redirect()->to('livewire/create/post');
}
public function edit_post($id)
{
$post = Post::whereId($id)->whereUserId(auth()->id())->first();
if ($post){
return redirect('livewire/edit/post/'.$id);
}
session()->flash('message',"you can't update not yours");
}/* END METHOD */
public function delete_post($id)
{
$post = Post::whereId($id)->whereUserId(auth()->id())->first();
if ($post){
if (File::exists('assets/images/'.$post->image)){
unlink('assets/images/'.$post->image);
}
$post->delete();
Session()->flash('message_success',"post deleted successfully");
}
Session()->flash('message_error',"you can't delete not yours");
} /* END METHOD */
public function show_post($id)
{
$post = Post::whereId($id)->first();
return view('livewire.show-post',['post' => $post]);
}
}
look to last function show_post it not work not back for me this view i shold make redirct like was before but i not like use more file , there solve for it? thanks for help
Please or to participate in this conversation.