I’ve made a very simple profile card with two views once is showing me the profile id,name and email and the second view just show the input fields for this three attributes.
This is working but it is “very” slow. When i’m hitting the button Edit on the show view, it takes more than 650ms(in best scenario, sometimes it takes more than 1.2sec) to load the edit view and vice versa.
How can I make this a little bit faster ?
Profile Component:
namespace App\Http\Livewire\User;
use App\User;
use Illuminate\Validation\Rule;
use Livewire\Component;
class Profile extends Component
{
public $user, $user_id, $name, $email;
public $updateMode = false;
public function mount(User $user)
{
$this->user = $user;
$this->user_id = $user->id;
$this->name = $user->name;
$this->email = $user->email;
}
public function render()
{
return view('livewire.user.profile.resource');
}
public function edit()
{
$this->updateMode = true;
}
public function cancel()
{
$this->updateMode = false;
}
public function submit()
{
$attributes = $this->validate([
'name' => 'required|min:6',
'email' => ['required', 'email', Rule::unique('users')->ignore($this->user->id)],
]);
$this->user->update($attributes);
$this->updateMode = false;
}
}
And this are the views:
resource.blade.php:
<div class="p-3">
#includeWhen(!$updateMode,'livewire.user.profile.show')
#includeWhen($updateMode,'livewire.user.profile.edit')
</div>
show.blade.php:
<div>
<div class="flex items-center py-2">
<div class="w-1/4">
<span class="text-gray-800">Id:</span>
</div>
<div class="w-3/4" >
<span class="text-gray-700 font-semibold">{{ $user_id }}</span>
</div>
</div>
<div class="flex items-center py-2">
<div class="w-1/4">
<span class="text-gray-800">Name:</span>
</div>
<div class="w-3/4" >
<span class="text-gray-700 font-semibold">{{ $name }}</span>
</div>
</div>
<div class="flex items-center py-2">
<div class="w-1/4">
<span class="text-gray-800">Email:</span>
</div>
<div class="w-3/4" >
<span class="text-gray-700 font-semibold">{{ $email }}</span>
</div>
</div>
<!-- Editing Buttons -->
<div class="pt-3">
<button type="button" wire:click.prevent="edit" class="py-1 px-2 rounded bg-blue-500 text-white font-semibold">Edit</button>
</div>
</div>
edit.blade.php:
<form wire:submit.prevent="submit">
<div class="flex items-center py-2">
<div class="w-1/4">
<span class="text-gray-800">Id:</span>
</div>
<div class="w-3/4" >
<span class="text-gray-700 font-semibold">{{ $user_id }}</span>
</div>
</div>
<div class="flex items-center py-2">
<div class="w-1/4">
<span class="text-gray-800">Name:</span>
</div>
<div class="w-3/4" >
<input type="text" class="w-1/2 border appearance-none py-1 px-2 rounded shadow focus:outline-none" wire:model="name">
</div>
</div>
<div class="flex items-center py-2">
<div class="w-1/4">
<span class="text-gray-800">Email:</span>
</div>
<div class="w-3/4" >
<input type="text" class="w-1/2 border appearance-none py-1 px-2 rounded shadow focus:outline-none" wire:model="email">
</div>
</div>
<!-- Editing Buttons -->
<div class="pt-3">
<button type="submit" class="py-1 px-2 rounded bg-blue-500 text-white font-semibold" >Save</button>
Cancel
</div>
</form>
I ran into the same issue, with the same implementation approach. I also noticed that it was a bit slow when Livewire would change the state to show/hide the form, so what I did was use Alpine.js for determining whether to show the form or not.
<div x-data="{ mode: 'view' }">
<div x-show="mode === 'edit'">
<div>
<!-- display form here -->
</div>
<button wire:click="update">
Save
</button>
<button #click.prevent="mode = 'view'">
Cancel
</button>
</div>
<div x-show="mode !== 'edit'">
<div>
<!-- profile displayed here -->
</div>
<button #click.prevent="mode = 'edit'">
Edit
</button>
</div>
</div>
Doing it this way resolved the issue with displaying the form, which feels really snappy and quick. I have run into a different issue since that I’m not sure how to address.
If I begin to type in the form to update the name, and quickly hit the save button before the requests to update the component properties complete, then what ever the properties were at the time that I hit the save button are what gets saved to the database, creating a race condition.
I’m still relatively new to the Livewire paradigm so I don’t have a good answer for this yet.
Related
how to display or call value in array in laravel blade view ?
I already have the data that appears in the image below:
enter image description here
I still don't understand how to call the data in the :
<h3>#currency($laporan->Total_Sayur)</h3>
I'm tired of trying it in various ways and it always appears another error message. Please help me
MyController
public function index()
{
$users = User::count();
$kelompok = Kelompok::count();
$anggota = Anggota::count();
$laporan = Anggota::select('kecamatan', Produk::raw('avg(total_sayur) as Total_Sayur, avg(total_buah) as Total_Buah,avg(total_ikan) as Total_Ikan, avg(total_ternak) as Total_Ternak'))
->leftjoin('produk', 'produk.anggota_id', '=', 'anggota.id')
->where('kecamatan', '=', 'Ngajum')
->GroupBy('kecamatan')
->get();
// return $laporan;
return view('Dashboard.index', compact('users', 'kelompok', 'anggota', 'laporan'));
}
View
<div class="row">
<div class="col-lg-3 col-6">
<!-- small box -->
<div class="small-box bg-info">
<div class="inner">
<h3>#currency($laporan->Total_Sayur)</h3>
<p>TOTAl KEMANFAATAN</p>
</div>
<div class="icon">
<i class="ion ion-pricetagg"></i>
</div>
More info <i class="fas fa-arrow-circle-right"></i>
</div>
</div>
</div>
Your solution start from here....
<div class="row">
<div class="col-lg-3 col-6">
#foreach($laporan as $item)
<!-- small box -->
<div class="small-box bg-info">
<div class="inner">
<h3>#currency($item->Total_Sayur)</h3>
<p>TOTAl KEMANFAATAN</p>
</div>
<div class="icon">
<i class="ion ion-pricetagg"></i>
</div>
More info <i class="fas fa-arrow-circle-right"></i>
</div>
#endforeach
</div>
</div>
I started with Laravel 8 and livewire a few days ago. I still have a lot to discover but I am on my way.
Lastly, I encountered a behaviour I have trouble understanding.
My goal
I want to create a page to CRUD posts. What I want is to have a post list that is paginated displayed at the bottom of the page, a button to create a new post and the possibility to click a button on each post line to edit the post.
I also want the editor of the post displayed at the top of the page while the list is hidden (but this last possibility is not absolutely necessary).
I could manage to have this working as long as the post list is not paginated but not with pagination.
To do this I use a liveewire component whose code is herebelow:
Component's code in app/Http/livewire/posts/Posts.php
<?php
namespace App\Http\Livewire\Posts;
use App\Models\Post;
use Livewire\Component;
class Posts extends Component
{
public $posts;
public $links;
public $post_id,$title, $abstract, $body,$category,$diaporama_dir,
$beg_date,$end_date,$close_date,$receive_registration,
$sticky,$user_id,$inscription_directive;
/**
* The attributes that are mass assignable.
*
* #var array
*/
public function render()
{
$this->mode='list';
$this->posts=Post::select('id','title')->orderBy('created_at','DESC')->paginate(15)->toArray();
$this->links=$this->posts['links'];
//dd($this->links);
$this->user_id=auth()->user()->id;
return view('livewire.posts.posts');
}
public function donothing(){
}
/*
* The attributes that are mass assignable.
*
* #var array
*/
public function resetInputFields(){
$this->title = '';
$this->body = '';
$this->title='';
$this->abstract='';
$this->body='';
$this->category='';
$this->diaporama_dir='';
$this->beg_date='';
$this->end_date='';
$this->close_date='';
$this->receive_registration='';
$this->sticky='';
$this->inscription_directive='';
}
/**
* The attributes that are mass assignable.
*
* #var array
*/
public function store()
{
$validatedData = $this->validate([
'title' => 'required',
'body' => 'required',
'abstract'=>'required',
'category'=>'',
'diaporama_dir'=>'',
'beg_date'=>'sometimes',
'end_date'=>'sometimes',
'close_date'=>'sometimes',
'receive_registration'=>'',
'sticky'=>'',
'user_id'=>'required',
'inscription_directive'=>''
]);
Post::create($validatedData);
session()->flash('message', 'Bravo ! Votre article a été enregistré.');
// $this->resetInputFields(); //user may want to keep the input stable
}
/**
* The attributes that are mass assignable.
*
* #var array
*/
public function edit($id)
{
$post = Post::findOrFail($id);
$this->post_id = $id;
$this->title = $post->title;
$this->abstract=$post->abstract;
$this->body=$post->body;
$this->category=$post->category;
$this->diaporama_dir=$post->diaporama_dir;
$this->beg_date=$post->beg_date;
$this->end_date=$post->end_date;
$this->close_date=$post->close_date;
$this->receive_registration=$post->receive_registration;
$this->sticky=$post->sticky;
$this->inscription_directive=$post->inscription_directive;
$this->dispatchBrowserEvent('notify','je passe en mode edit');//to switch browser page to edit mode
}
/**
* The attributes that are mass assignable.
*
* #var array
*/
public function update()
{
$validatedData = $this->validate([
'title' => 'required',
'body' => 'required',
'abstract'=>'required',
'category'=>'',
'diaporama_dir'=>'',
'beg_date'=>'sometimes',
'end_date'=>'sometimes',
'close_date'=>'sometimes',
'receive_registration'=>'',
'sticky'=>'',
'user_id'=>'required',
'inscription_directive'=>''
]);
$post = Post::find($this->post_id);
$post->update([
'title' => $this->title,
'body'=> $this->body,
'abstract'=> $this->abstract,
'category'=> $this->category,
'diaporama_dir'=>$this->diaporama_dir,
'beg_date'=>$this->beg_date,
'end_date'=>$this->end_date,
'close_date'=>$this->close_date,
'receive_registration'=>$this->receive_registration,
'sticky'=>$this->sticky,
'user_id'=>$this->user_id,
'inscription_directive'=>$this->inscription_directive
]);
session()->flash('message', "Bravo ! L'article a été mis à jour.");
// $this->resetInputFields();//user may like to keep the input fields stable
}
}
and views are these:
View 1 : the main page in resources/views/livewire/posts/posts.blade.php
<div class="container m-auto w-10/12">
<div x-data="{ mode: 'list' }">
#if (session()->has('message'))
<div class="bg-green-200 p-4 w-full my-8 text-xl text-orange-500">
{{ session('message') }}
</div>
#endif
<div x-on:notify.window="mode = 'update'">
<div x-show="mode==='update'">
#include('livewire.posts.update')
</div>
<div x-show="mode === 'edit'">
#include('livewire.posts.create')
</div>
</div>
{{-- <div x-show="mode === 'list'" class="">--}}
<div>
<div>
<button x-on:click="mode = 'edit'" class="bg-red-400 px-2 py-1 border rounded-lg mt-2">Nouvel
article</button>
</div>
<table class=" bg-green-400 w-full table table-bordered mt-5 ">
<thead>
<tr class="bg-red-50 mb-2">
<th>Id.</th>
<th>Titre</th>
<th width="150px">Action</th>
</tr>
</thead>
<tbody>
#for ($i = 0; $i < $posts['per_page']; $i++)
<tr class="bg-red-400 mb-2 p-2 space-y-2 border-8 border-red-50 ">
<td>{{ $posts['data'][$i]['id'] }}</td>
<td>{{ $posts['data'][$i]['title'] }}</td>
<td>{{--les actions--}}
<button wire:click="edit({{ $posts['data'][$i]['id'] }})"
class="btn btn-primary btn-sm">Edit</button>
{{-- <button wire:click="delete({{ $post->id }})"
class="btn btn-danger btn-sm">Delete</button>--}}
</td>
</tr>
#endfor
</tbody>
</table>
<div class="flex flex-row mt-2">
#for ($i = 0; $i < count($links); $i++)
<div class="flex p-2 mr-2 border w-max-content">
{{$links[$i]['label']}}
</div>
#endfor
</div>
</div>
</div>
2- create include in resources/views/livewire/posts/create.blade.php
<div class="container bg-green-500 p-4">
<form>
This is the create form
<input type="hidden" name="user_id" wire:model="user_id" >
<div class="flex flex-col md:flex-row" >
<div class=" mt-2 flex flex-col w-max-content">
<label for="category">Catégorie:</label>
<select class="" name="category" id="category" wire:model="category">
<option value="Sans">Sans</option>
<option value="Annoncement">Annonce d'un événement</option>
</select>
#error('category') <span class="text-danger">{{ $message }}</span>#enderror
</div>
<div class=" mt-2 flex flex-col flex-auto ml-4">
<label for="title">Title:</label>
<input type="text" class="form-control" name="title" id="title" placeholder="Saisissez un titre"
wire:model="title" value="">
#error('title') <span class="text-danger">{{ $message }}</span>#enderror
</div>
</div>
<div class="flex flex-col md:flex-row" >
<div class=" mt-2 flex flex-col w-max-cbeg_date ">
<label for="beg_date">Date de début</label>
<input type="text" class="" name="beg_date" id="beg_date" wire:model="beg_date">
#error('beg_date') <span class="text-danger">{{ $message }}</span>#enderror
</div>
<div class=" mt-2 flex flex-col w-max-cbeg_date ml-4">
<label for="end_date">Datend_date</label>
<input type="text" class="" name="end_date" id="end_date" wire:model="end_date">
#error('end_date') <span class="text-danger">{{ $message }}</span>#enderror
</div>
<div class=" mt-2 flex flex-col w-max-cbeg_date ml-4">
<label for="close_dclose">Date limite</label>
<input type="text" class="" name="close_date" id="close_date" wire:model="close_date">
#error('close_date') <span class="text-danger">{{ $message }}</span>#enderror
</div>
<div class=" mt-2 flex flex-col w-max-content ml-4">
<label for="receive_registration">Accepte les inscriptions:</label>
<select class="" name="receive_registration" id="receive_registration" wire:model="receive_registration">
<option value="no">Non</option>
<option value="yes">Oui</option>
</select>
#error('receive_registration') <span class="text-danger">{{ $message }}</span>#enderror
</div>
<div class=" mt-2 flex flex-col flex-auto ml-4">
<label for="title">Dossier du diaporama</label>
<input type="text" class="form-control" name="diaporama_dir" id="diaporama_dir" placeholder="ex: admin/1"
wire:model="diaporama_dir">
#error('diaporama_dir') <span class="text-danger">{{ $message }}</span>#enderror
</div>
</div>
<div class="mt-2 flex flex-col">
<label for="abstract">Résumé</label>
<textarea class="form-control" name="abstract" id="abstract" wire:model="abstract"
placeholder="Saisissez votre article"></textarea>
#error('abstract') <span class="text-danger">{{ $message }}</span>#enderror
</div>
<div class="mt-2 flex flex-col">
<label for="body">Corps de l'article</label>
<textarea class="form-control" name="body" id="body" wire:model="body" rows=30
placeholder="Saisissez votre article"></textarea>
#error('body') <span class="text-danger">{{ $message }}</span>#enderror
</div>
<button wire:click.prevent="store()" class="bg-red-400 px-2 py-1 border rounded-lg mt-2">Enregistrer</button>
<button wire:click.prevent="resetInputFields()" class="bg-red-400 px-2 py-1 border rounded-lg mt-2">Effacer tout</button>
<button #click.prevent="mode = 'list'" class="bg-red-400 px-2 py-1 border rounded-lg mt-2 ml-16">Retour à la liste</button>
</form>
update include
The update include is exactly the same as the create include except an additional hidden field for the post id.
What is happening?
At startup, I mean when I visit the localhost:8000/posts page, the page 1 is correctly displayed and the links at the bottom of the page are like localhost:8000/posts?page=3 whichever the number of the page may be.
From this page I can normally go to another page using the bottom links, and this several times.
The troube arises when I click a link to edit a post. The post is correctly sent back by the server but instantly we are switched to page 1 of the paginated posts and the bottom links take a strange form such as localhost:8000/livewire/message/posts.posts?page=3 wichever the page number may be.
The trouble arises also when, after having displayed the create form, I type a first char in the fields. In fact it seems that it arises each time a sync is required.
How can I fix this?
replace
<div class="flex flex-row mt-2">
#for ($i = 0; $i < count($links); $i++)
<div class="flex p-2 mr-2 border w-max-content">
{{$links[$i]['label']}}
</div>
#endfor
</div>
with
<div class="flex flex-row mt-2">
{{ $posts->links() }}
</div>
and in component
use WithPagination;
ref link https://laravel-livewire.com/docs/2.x/pagination
I want to update multiple record related to project and I have already made logic for store data in controller; it's perfectly adding multiple record but I have no idea how to do so.
I want to also update multiple record that already exist in database.
https://ibb.co/sjNKMzJ
Model Issue
public function project()
{
return $this->hasOne('App\Project','project_id',id)
}
Model Project
public function issue()
{
return $this->hasMany('App\Issue','id','project_id')
}
return response
// http://localhost/hourlog/cms/public/projects/43/issues/update
{
"_token": "S6typbw0hywPqaUdxCTqWeJNieyl3VieQhCHqDZ7",
"date": [
"2020-07-06",
"2020-07-22",
"2020-07-11"
],
"issue": [
"edit issue",
"delete issue on web",
"update issue on cms"
]
}
Controller
public function issuesUpdate(Request $request, Project $project)
{
$issues =Issue::where('project_id',$project->id)->get();
//for add new record
foreach($request->date as $key2 => $val){
$issue = new Issue;
$issue->date = $val;
$issue->issue = $request->issue[$key2];
$issue->project_id = $project->id;
$issue->save();
}
return redirect()->route('project');
}
html view
<form action="{{ route('project.issues.update',[$project->id])}}" method="POST">
#csrf
<div class="portlet">
<div class="portlet-heading bg-light-theme">
<h3 class="portlet-title">
<span class="ti-user mr-2">
</span>Add Issues
</h3>
<div class="portlet-widgets">
<span class="divider">
</span>
<button type="submit" class="btn btn-white waves-effect btn-rounded">
<span class="btn-label">
<i class="fa fa-save">
</i>
</span> Save
</button>
</div>
<div class="clearfix">
</div>
</div>
<div id="bg-inverse" class="panel-collapse collapse show" style="">
<div class="portlet-body">
<div class="card-box">
<div class="row">
<div class="col-md-12 mt20">
<div class="addMore">
<div class="addmore_cont">
<div class="addMore_btn">
<div class="mt12 pull-right">
<button type="button" title="Add More" class="btn btn-success waves-effect
waves-light btn-sm add_more" data-key="">
<i class="fa fa-plus">
</i>
</button>
</div>
<div class="row addmore_issues">
<div class="col-md-12">
#if(count($issues))
#foreach($issues as $key => $details)
<div class="row">
<div class="col-md-5">
<div class="form-group">
<input required type="date" value="{{$details->date}}"
name="date[]" class="form-control"
aria-describedby="emailHelp" >
</div>
</div>
<div class="col-md-5">
<div class="form-group">
<input required type="text" value="{{$details->issue}}"
name="issue[]" class="form-control"
aria-describedby="emailHelp" placeholder="Issue...">
</div>
</div>
<div class="col-md-1 mt12">
<button type="button" class="btn btn-danger waves-effect waves-
light btn-sm delete">
<i
class="fa fa-times">
</i>
</button>
</div>
</div>
#endforeach
#else
<div class="row">
<div class="col-md-5">
<div class="form-group">
<input required type="date" value="" name="date[]" class="form-control"
aria-describedby="emailHelp" >
</div>
</div>
<div class="col-md-5">
<div class="form-group">
<input required type="text" value="" name="issue[]" class="form-control"
aria-describedby="emailHelp" placeholder="Issue...">
</div>
</div>
</div>
#endif
</div>
</div>
<!--end row-->
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</form>
Route
Route::post('/projects/{project}/issues/update', "ProjectController#issuesUpdate")-
>name('project.issues.update');
First change your data format from
"date": [
"2020-07-06",
"2020-07-22",
"2020-07-11"
],
"issue": [
"edit issue",
"delete issue on web",
"update issue on cms"
]
To
[
["date"=>"2020-07-06","issue"=>"edit issue"],
["date"=>"2020-07-22","issue"=>"delete issue on web"],
["date"=>"2020-07-11","issue"=>"update issue on cms"]
]
And you can make it by using like below html format
<input required type="date" value="{{$details->date}}"
name="issues[{{$key}}][date]" class="form-control"
aria-describedby="emailHelp" >
Inside Controller
public function issuesUpdate(Request $request, Project $project)
{
$issues = $request->issues;
$insertData = [];
foreach($issues as $key=>$issue){
$issue["project_id"] = $project->id;
$insertData[] = $issue;
}
Issue::where('project_id',$project->id)->delete();// to not insert duplicate issues for the same project
Issue::insert($insertData);
return redirect()->route('project');
}
I am using session flash in my Laravel-5.8 project.
Controller
<?php
namespace App\Http\Controllers\Appraisal;
use App\Http\Controllers\Controller;
use App\Models\Appraisal\AppraisalSkill;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Exception;
use Illuminate\Support\Facades\Validator;
use Session;
class AppraisalSkillsController extends Controller
{
public function create()
{
abort_unless(\Gate::allows('skill_create'), 403);
return view('appraisal.skills.create');
}
public function store(Request $request)
{
abort_unless(\Gate::allows('skill_create'), 403);
$this->validate($request, [
'skill_name' => 'required|unique:appraisal_skills,company_id',
]);
$skill = AppraisalSkill::create([
'skill_name' => $request->skill_name,
'description' => $request->description,
'company_id' => Auth::user()->company_id,
'created_by' => Auth::user()->id,
'created_at' => date("Y-m-d H:i:s"),
'is_active' => 1,
]);
Session::flash('success', 'Appraisal Skill is created successfully');
return redirect()->route('appraisal.skills.index');
}
}
view/partials/_messages.blade.php
#if (count($errors) > 0)
<div class="alert alert-danger alert-block" role="alert">
<button type="button" class="close" data-dismiss="alert">×</button>
<strong>Errors: </strong>
<ul>
#foreach ($errors as $error)
<li>{{ $error }}</li>
#endforeach
</ul>
</div>
#endif
#if (Session::has('success'))
<div class="alert alert-success" role="alert">
<button type="button" class="close" data-dismiss="alert">×</button>
<strong>Success: </strong>{{Session::get('success')}}
</div>
#endif
view
<div class="container-fluid">
<div class="panel-heading clearfix">
<div class="float-right">
<div class="btn-group btn-group-sm" role="group">
<a href="{{ route("appraisal.skills.index") }}" class="btn bg-navy margin" title=" Back">
<span> Back to List</span>
</a>
</div>
</div>
</div>
<br>
#include('partials._messages')
<br>
<div class="card">
<div class="card-header">
Create Skill
</div>
<div class="card-body">
<form action="{{route('appraisal.skills.store')}}" method="post" class="form-horizontal" enctype="multipart/form-data">
{{csrf_field()}}
<div class="form-body">
<div class="row">
<div class="col-md-6">
<div class="form-group row">
<label class="control-label text-right col-md-3">Skill Name<span style="color:red;">*</span></label>
<div class="col-md-9 controls">
<input type="text" name="skill_name" placeholder="Enter skill name here" class="form-control" value="{{old('skill_name')}}">
</div>
</div>
</div>
<div class="col-md-6">
<div class="form-group row">
<label class="control-label text-right col-md-3">Description</label>
<div class="col-md-9">
<textarea rows="2" name="description" class="form-control" placeholder="Enter Description here" value="{{old('description')}}"></textarea>
</div>
</div>
</div>
</div>
</div>
<div>
<button type="submit" class="btn btn-primary">{{ trans('global.save') }}</button>
<button type="button" onclick="window.location.href='{{route('appraisal.skills.index')}}'" class="btn btn-default">Cancel</button>
</div>
</form>
</div>
</div>
</div>
When I click on save submit button, I expect that if there is any error it should display the detail of the error. But, rather it only display Error: without the details.
The success message is working, but the error message is not working as expected
How do I get this resolved?
Thank you.
There is a little mistake when looping through the errors. Change line #foreach ($errors as $error) to #foreach ($errors->all() as $error) . It should work now!
i'm setting up a new project to perform multi language form but i'm stuck in edit form i don't know how to handle that
I created my controller and create view the only thing i need is edit view
so you can check my create view in bellow that work fine :
<div class="card-body text-center">
{!! Form::open(['route' => 'content.store', 'method' => 'Post']) !!}
<div class="card">
<div class="card-body">
<div class="form-group">
<label class="mx-4" for="my-input">{{ __('content/form.country_t') }}:</label>
<input id="my-input " type="text" name="country" placeholder="{{ __('content/form.country') }}">
<label class="mx-4" for="my-input">{{ __('content/form.city_t') }}:</label>
<input id="my-input" type="text" name="city" placeholder="{{ __('content/form.city') }}">
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="card col-xs-12 p-0">
<nav>
<div class="nav nav-pills nav-fill card-header" id="nav-tab" role="tablist">
#foreach (config('translatable.locales') as $la=>$desc)
<a class="nav-item nav-link" id="nav-home-tab" data-toggle="tab" href="#{{ $la }}" role="tab" aria-controls="nav-home" aria-selected="true">{{ $desc }}</a> #endforeach
</div>
<div class="tab-content py-3 px-3 px-sm-0 card-body" id="nav-tabContent">
#foreach (config('translatable.locales') as $la=>$desc)
<div class="tab-pane fade px-4" id="{{ $la }}" role="tabpanel" aria-labelledby="nav-home-tab">
<div class="form-group">
<label for="my-input" class="">{{ __('content/form.title') }}</label>
<input id="my-input" class="form-control" type="text" name="translations[{{ $la }}][title]">
</div>
<div class="form-group">
<label for="my-input" class="">{{ __('content/form.body') }}</label>
<input id="my-input" class="form-control" type="text" name="translations[{{ $la }}][body]">
</div>
</div>
#endforeach
</div>
</nav>
</div>
<button type="submit" class="row col-12 mt-2 mx-auto btn btn-primary">{{ __('content/form.submit') }}</button>
</div>
</div>
</div>
</div>
{!! Form::close() !!}
</div>
and this is my controller :
public function store(Request $request)
{
$contents = new Content;
// $contents->fill($request->all());
$this->fillRequest($request,$contents);
$contents->User()->associate(\Auth::user());
$contents->saveOrFail();
return redirect()->route('content.index')->with('success','با موفقیت ساخته شد');
}
private function fillRequest(Request $request, Content $model)
{
//fill model on fillable variables
$model->fill($request->only($model->getFillable()));
$model->saveOrFail();
foreach ($request->translations as $la => $desc) {
//if title field is null ignore the translations
// in case of there is a translation... delete it
if (!$desc["title"]) {
if ($model->hasTranslation($la)) {
$model->deleteTranslations($la);
}
continue;
}
//create new translation if not exists
$model->translateOrNew($la)->fill($desc);
$model->saveOrFail();
}
return $model;
}
I need to know how can i create edit view exactly same as my create view above