where are you using livewire?
Oct 31, 2020
4
Level 11
Livewire form submit
Hello everyone.
I'm working on a basic crud application, just to get used to the new Laravel Livewire features of 8.0
At the moment I'm struggling. I've basically copied and pasted bits of code just so I can understand it more.
This is my code: It's designed to submit the form using livewire then handle it in the controller. However the post is successful but I get redirected back with a "?" in the url.
my create.blade.php:
<x-app-layout>
<x-slot name="header">
<h2 class="font-semibold text-xl text-gray-800 leading-tight">
Add Creature
</h2>
</x-slot>
<div class="max-w-7xl mx-auto py-10 sm:px-6 lg:px-8">
<x-jet-form-section submit="store">
<x-slot name="title">
{{ __('Creature\'s Information') }}
</x-slot>
<x-slot name="description">
{{ __('These are your creature\'s basic information.') }}
</x-slot>
<x-slot name="form">
<!-- Name -->
<div class="col-span-6 sm:col-span-4">
<x-jet-label for="name" value="{{ __('Name') }}" />
<x-jet-input id="name" type="text" class="mt-1 block w-full" wire:model.defer="state.name" autocomplete="off" />
<x-jet-input-error for="name" class="mt-2" />
</div>
</x-slot>
<!-- Submit -->
<x-slot name="actions">
<x-jet-button type="submit">
{{ __('Add Creature') }}
</x-jet-button>
</x-slot>
</x-jet-form-section>
</div>
</x-app-layout>
my creatures controller is:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Creature;
use Illuminate\Support\Facades\Validator;
class CreatureController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$creatures = Creature::get();
return view('creatures.index', compact('creatures'));
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
return view('creatures.create');
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$validator = Validator::make($request->all(), [
'name' => 'required|max:255',
]);
if ($validator->fails()) {
return redirect('creatures/create')
->withErrors($validator)
->withInput();
}
dd($request->all());
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
//
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
//
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
//
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
//
}
}
Please or to participate in this conversation.