Last active
November 22, 2023 16:20
-
-
Save filippotoso/b9c85c0e51f11d43c815912bd54359e7 to your computer and use it in GitHub Desktop.
Embrace the Larabel backend (with Livewire)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Support\Livewire; | |
use FilippoToso\Domain\Livewire\Component as BaseComponent; | |
use Illuminate\Support\Facades\View; | |
class Component extends BaseComponent | |
{ | |
public function __construct() | |
{ | |
if ($errors = View::shared('errors')) { | |
$this->setErrorBag($errors->getBag('default')); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function previous(string $key, mixed $default = null): mixed | |
{ | |
$request = request(); | |
$session = session(); | |
if ($session->hasOldInput($key)) { | |
return $session->getOldInput($key); | |
} | |
if ($request->has($key)) { | |
return $request->input($key); | |
} | |
return $default; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Backend\Posts\Livewire; | |
use Support\Livewire\Component; | |
use Support\Models\Post; | |
class PostEditor extends Component | |
{ | |
public $title; | |
public $content; | |
/** | |
* @param User $utente | |
* @return void | |
*/ | |
public function mount(Post $post) | |
{ | |
$this->title = previous('title', $post->title); | |
$this->description = previous('title', $post->description); | |
} | |
/** | |
* Get the view / contents that represent the component. | |
* @return View|Closure|string | |
*/ | |
public function render() | |
{ | |
return view('backend.posts.post-editor'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment