Skip to content

Instantly share code, notes, and snippets.

@exileed
Forked from brain2xml/WordController.php
Last active March 8, 2022 11:04
Show Gist options
  • Save exileed/d15f3a90d30d93255f5602bebde9871e to your computer and use it in GitHub Desktop.
Save exileed/d15f3a90d30d93255f5602bebde9871e to your computer and use it in GitHub Desktop.
@extends('layout')
@section('content')
<div class="container">
<h1>Add new word</h1>
@include('words.form', ['word' => $word, 'method'=>'create'])
</div>
@endsection
@extends('layout')
@section('content')
<div class="container">
<h1>Edit {{ $word->id }}</h1>
@include('words.form', ['word' => $word, 'method'=>'update'])
<div class="row">
or
<form method="{{ route('words.destroy', ['word'=>$word->id]) }}">
@csrf
@method('DELETE')
<input type="submit" value="Delete" />
</form>
</div>
</div>
@endsection
@if (count($errors) > 0)
<div class="error">
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
<form action="{{ $word->id == null ? route('words.store') : route('words.update', ['word'=>$word->id]) }}" method="post">
@csrf
@isset($word->id)
{{ method_field('PATCH')}}
@endisset
<div class="mb-3 col-lg-4">
<label for="f1" class="form-label">English</label>
<input id="f1" type="text" class="form-control {{ $errors->has('english') ? 'is-invalid' : '' }}" name="english" value="{!! old('english', optional($word)->english) !!}" />
@error('english')
<div class="form-text">{{ $errors->first('english') }}</div>
@enderror
</div>
<div class="mb-3 col-lg-4">
<label for="f2" class="form-label">Spanish</label>
<input id="f2" type="text" class="form-control {{ $errors->has('spanish') ? 'is-invalid' : '' }}" name="spanish" value="{!! old('spanish', optional($word)->spanish) !!}" />
@error('english')
<div class="form-text">{{ $errors->first('spanish') }}</div>
@enderror
</div>
<div class="mb-3 col-lg-4">
<label for="f3" class="form-label">Turkish</label>
<input id="f3" type="text" class="form-control {{ $errors->has('turkish') ? 'is-invalid' : '' }}" name="turkish" value="{!! old('turkish', optional($word)->turkish) !!}" />
@error('english')
<div class="form-text">{{ $errors->first('turkish') }}</div>
@enderror
</div>
<div class="mb-3 col-lg-4">
<label for="f4" class="form-label">Russian</label>
<input id="f4" type="text" class="form-control {{ $errors->has('russian') ? 'is-invalid' : '' }}" name="russian" value="{!! old('russian', optional($word)->russian) !!}" />
@error('english')
<div class="form-text">{{ $errors->first('russian') }}</div>
@enderror
</div>
<div>
<input type="submit" value="Save" />
</div>
</form>
<?php
namespace App\Http\Controllers;
use App\Http\Requests\StoreWordRequest;
use App\Http\Requests\UpdateWordRequest;
use App\Models\Word;
class WordController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$words = Word::paginate('15');
return view('words.list', ['words'=>$words]);
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
return view('words.create', ['word'=>new Word()]);
}
/**
* Store a newly created resource in storage.
*
* @param \App\Http\Requests\StoreWordRequest $request
* @return \Illuminate\Http\Response
*/
public function store(StoreWordRequest $request)
{
Word::create($request->all());
return redirect()->route('words.index');
}
/**
* Display the specified resource.
*
* @param \App\Models\Word $word
* @return \Illuminate\Http\Response
*/
public function show(Word $word)
{
}
/**
* Show the form for editing the specified resource.
*
* @param \App\Models\Word $word
* @return \Illuminate\Http\Response
*/
public function edit(Word $word)
{
return view('words.edit', ['word'=> $word]);
}
/**
* Update the specified resource in storage.
*
* @param \App\Http\Requests\UpdateWordRequest $request
* @param \App\Models\Word $word
* @return \Illuminate\Http\Response
*/
public function update(UpdateWordRequest $request, Word $word)
{
$word->updateOrFail($request->all());
return redirect()->route('words.index');
}
/**
* Remove the specified resource from storage.
*
* @param \App\Models\Word $word
* @return \Illuminate\Http\Response
*/
public function destroy(Word $word)
{
//
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment