Skip to content

Instantly share code, notes, and snippets.

@filippotoso
Last active November 22, 2023 16:20
Show Gist options
  • Save filippotoso/b9c85c0e51f11d43c815912bd54359e7 to your computer and use it in GitHub Desktop.
Save filippotoso/b9c85c0e51f11d43c815912bd54359e7 to your computer and use it in GitHub Desktop.
Embrace the Larabel backend (with Livewire)
<?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'));
}
}
}
<?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;
}
<?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