My update function in the resource controller
public function update(UpdateOeuvreRequest $request, Oeuvre $oeuvre)
{
$oeuvre->titre = $request->input('titre');
$oeuvre->auteur = $request->input('auteur');
$oeuvre->annee = $request->input('annee');
$oeuvre->description = $request->input('description');
$oeuvre->category_id = $request->input('category_id');
$oeuvre->qt = $request->input('qt');
$query=$oeuvre->save();
if($query){
return redirect()->route('Oeuvre')->with('success','updated successfuly');
}
}
MY edit.blade.php
<form action="{{ route('Oeuvre.update',$oeuvre) }}" enctype="multipart/form-data" method="POST">
#csrf
#method('PUT')
<div class="row mb-3">
<div class="col-md-6">
<div class="form-floating mb-3 mb-md-0">
<input class="form-control" value="{{$oeuvre->titre}}" name="titre" type="text" placeholder="titre" />
<label for="titre">Titre</label>
</div>
</div>
<div class="col-md-6">
<div class="form-floating">
<input class="form-control" value="{{$oeuvre->auteur}}" name="auteur" type="text" placeholder="auteur" />
<label for="auteur">Auteur</label>
</div>
</div>
I think what is happening is that you are using this parameter in your controller =>
$oeuvre
Then you have to pass it also through your form and route
Related
i have a problem where the value isn't calculated.
I have function where the user able to update Weight/size and quantity(if the input isn't in readonly). When the user enter a new weight/size it will be auto-calculated in the Order Total. Apparently, there is a value already in the Order Total (since it is an update) so i want it to auto update the value in the order total when the user update the new input in weight/size or quantity.
pls click this picture
here is my updates.blade.php
<div class="col-sm-12 col-md-6" >
<div class="card">
<div class="card-body">
<div class="form-actions">
<div class="container" style="padding: 0;margin: 0;">
<div class="row">
<div class="col-sm-6" >
<span class="float-sm-left">
<h3 class="card-title">Update Order</h3>
</span>
</div>
</div>
</div>
</div>
</br>
<form action="" method="POST" >
#csrf
#method('PUT')
<div class="form-row">
<div class="col-md-4 mb-3">
<label for="validationTooltip01">Order ID</label>
<input type="text" class="form-control" wire:model="orderID" value="" readonly>
</div>
<div class="col-md-4 mb-3">
<label for="validationTooltip02">Order Date</label>
<input type="text" class="form-control" wire:model="orderDate" value="" readonly>
</div>
<div class="col-md-4 mb-3">
<label for="validationTooltipUsername">Order Status</label>
<input type="text" class="form-control" wire:model="orderStatus" value="" readonly>
</div>
</div>
<div class="form-row">
<div class="col-md-6 mb-3">
<label class="form-control-label" >Customer Phone Number</label>
<input type="text" name="" value="" class="form-control" maxlength="11" wire:model="custPhone" readonly>
</div>
<div class="col-md-6 mb-3">
<label class="form-control-label" >Customer Name</label>
<input type="text" name="" value="" class="form-control" maxlength="11" wire:model="custName" readonly>
</div>
</div>
<div class="form-row">
#foreach($serviceOrder as $o)
<div class="col-md-5 mb-3">
<label class="form-control-label" >Service {{ $loop->iteration }} </label>
<input type="text" wire:model="serviceOrder.{{ $loop->index }}.serv.serviceName" class="form-control " readonly>
</div>
<input type="hidden" wire:model="serviceOrder.{{ $loop->index }}.serv.servicePrice" class="form-control col-sm-1 mb-3" readonly>
<div class="col-md-3 mb-3">
<label class="form-control-label" >Weight/Size</label>
<input type="text" name="" value="" wire:model="serviceOrder.{{ $loop->index }}.weightsize" class="form-control">
</div>
<div class="col-md-3 mb-3">
<label class="form-control-label" >Quantity*opt</label>
<input type="text" name="" value="" wire:model="serviceOrder.{{ $loop->index }}.quantity" class="form-control" #if(!$serviceOrder[$loop->index]['quantity']) readonly #endif >
</div>
#endforeach
</div>
<label class="form-control-label" >Order Total RM</label>
<input type="number" wire:model="orderTotal" value="" class="form-control" readonly>
</br>
<div class="form-actions">
<div class="container" style="padding: 0;margin: 0;">
<div class="row">
<div class="col-sm-6" >
<span class="float-sm-left">
<a class="btn btn-primary" href="{{ route('orders.indexInProcess') }}"> Back</a>
</span>
</div>
<div class="col-sm-6">
<span class="float-sm-right">
<div class="text-right">
<button type="submit" class="btn btn-info mr-2">Update</button>
<button type="reset" class="btn btn-dark float-right">Reset</button>
</div>
</span>
</div>
</div>
</div>
</div>
</form>
</div>
</div>
here is the livewire updates.php
<?php
namespace App\Http\Livewire;
use Livewire\Component;
use App\Customer;
use App\Service;
use App\Order;
use App\ServiceOrder;
class Updates extends Component
{
public $orders;
public $orderID;
public $orderDate;
public $orderStatus;
public $orderTotal;
public $custName;
public $custPhone;
public $serviceName;
public $servicePrice;
public $weightsize;
public $quantity;
public $serviceOrder;
public function mount($order,$so)
{
//$orders = Order::with('customer')->get();
//ServiceOrder::with('serv')->where('order_id', $order->id)->get();
$this->orderID = $order->id;
$this->orderDate = $order->orderDate;
$this->orderStatus = $order->orderStatus;
$this->orderTotal = $order->orderTotal;
$this->custPhone = $order->customer->custPhone;
$this->custName = $order->customer->custName;
$this->serviceOrder = $so->toArray();
//dd($this->serviceOrder);
//$so->serviceName,
//$so->weightsize,
//$so->quantity
}
public function render()
{
//$so = ServiceOrder::with('serv')->where('order_id', $order->id)->get();
return view('livewire.updates');
}
public function updatedInputs($name)
{
$array = explode('.', $name);
if ($array[1] == 'serviceName') {
$this->inputs[$array[0]]['servicePrice'] = $this->services->find($value)->servicePrice;
}
try {
$this->calculateTotal();
} catch (\Exception $e) {
}
}
// perform calculation here.
public function calculateTotal(){
$this->orderTotal = $this->orderTotal;
foreach ($this->serviceOrder as $item) {
if($item['quantity'] == ''){
$item['optQuantity']= 1;
$this->orderTotal += ($item['servicePrice'] * $item['weightsize']) * ($item['quantity']);
}else{
$this->orderTotal += $item['servicePrice'] * ($item['weightsize']) * ($item['quantity']);
}
//$this->total *= $item['optQuantity']; // * price;
}
}
}
please help me out here T.T
You can fire event from component (for example) and then register listener in class and call a method for updating total. Check documentation for that.
"Apparently, there is a value already in the Order Total (since it is an update) so i want it to auto update the value in the order total when the user update the new input in weight/size or quantity."
So, the problem is $orderTotal only update once? it doesn't update when user update new input?. Livewire should render everytime there is action or any input.
First of all, i advice u to check what happen when to your function when user update the new input with dd function.
public function calculateTotal(){
dd('is this func work?');
$this->orderTotal = $this->orderTotal;
foreach ($this->serviceOrder as $item) {
if($item['quantity'] == ''){
$item['optQuantity']= 1;
$this->orderTotal += ($item['servicePrice'] * $item['weightsize']) * ($item['quantity']);
}else{
$this->orderTotal += $item['servicePrice'] * ($item['weightsize']) * ($item['quantity']);
}
//$this->total *= $item['optQuantity']; // * price;
}
}
After you debug your function, maybe you already found the answer you looking for or you can come back and ask me anything. ^^
I tried to create adding/creating a new menu and saved it in the database. However, when I clicked the button, my system didn't show any error but the data is not saved in the database.
adminAddMenu.blade.php
<form>
#csrf
<div class="form-group row">
<label for="categorycode" class="col-sm-3 col-form-label">Category Code</label>
<div class="col-md-4">
<input name="category_code" value="{{old('category_code')}}" class="form-control">
</div>
</div>
<div class="form-group row">
<label for="menutitle" class="col-sm-3 col-form-label">Menu Title</label>
<div class="col-md-4">
<input name="menu_title" value="{{old('menu_title')}}" class="form-control">
</div>
</div>
<div class="form-group row">
<label for="menuprice" class="col-sm-3 col-form-label">Menu Price</label>
<div class="col-md-4">
<textarea name = "menu_price" value="{{old('menu_price')}}" class="form-control"></textarea>
</div>
</div>
<div class="form-group row">
<div class="offset-sm-3 col-sm-9">
<button type="submit" class="btn btn-primary" href="">Submit</button>
</div>
</div>
</div>
</form>
AdminMenuController.php
public function store(Request $request)
{
$menu = new \App\Menu;
$menu->category_code = $request->category_code;
$menu->menu_title = $request->menu_title;
$menu->menu_price = $request->menu_price;
$menu->save();
Session::flash('flash_message', 'Menu is successful! added');
return redirect()->back();
}
web.php
Route::resource('/menus', 'AdminMenuController');
You don't give the form action method where your data will submit. Like you want to send your form data to store method in your controller. So you have to write follow:
<form method="POST" action="{{ route('your route name') }}">
I think you miss the action attribute of your form. Please add action to your form
<form action="{{ YOUR_ROUTER }}">
...
Please add action on form tag.
Like as-
<form action={{ route("your route write here") }} method="post">
I think now it's work's.
How do I introduce a trix field inside of an existing model? For example, the model has a title, a subtitle, and a paragraph, which I want to be filled with trix. Until now I had a different model for the trix text.
class Text_box extends Model{
protected $table = 'TextBox';
protected $fillable = [
'id', 'pages_id','title','subtitle','text'
];}
I want text to be a trix field.
<form method="POST" enctype="multipart/form-data" action="/textbox/{{$page->id}}">
#csrf
<div class="form-group row">
<label for="titlu" class="col-md-4 col-form-label text-md-right">Titlu</label>
<div class="col-md-6">
<input id="titlu" type="text" min="0" class="form-control" name="titlu" required autocomplete="titlu" placeholder="*optional*">
</div>
</div>
<div class="form-group row">
<label for="autor" class="col-md-4 col-form-label text-md-right">Autor</label>
<div class="col-md-6">
<input id="autor" type="text" min="0" class="form-control" name="autor" required autocomplete="autor" placeholder="*optional*">
</div>
</div>
<div style = "height: 50px;"></div>
<div class="row">
<div class="col-lg">
<input id="tb" type="hidden" name="textbox">
<trix-editor input="tb"></trix-editor>
</div>
</div>
<div style = "height: 30px;"></div>
<div class="form-group row">
<div class="col-sm">
<button type="submit" class="btn btn-primary col-sm-2 float-right">
{{ __('Submit') }}
</button>
</div>
</div>
This is my form.
public function add_textbox(Request $request, $id)
{
$trix = request()->input('textbox');
return $trix;
$textbox = Text_box::create([
'title' => $request['titlu'],
'subtitle' => $request['autor'],
'text' => $trix['text'],
'pages_id' => $id
]);
$page = Pages::where('id',$id)->first();
$w = json_decode($page->widgets,true);
if($w)
array_push($w,['textbox',$textbox->id]);
else
$w[] = ['textbox',$textbox->id];
$page->widgets = json_encode($w);
$page->save();
return redirect('/edit/'.$id);
}
This is my controller.
The $trix var is empty.
when you have it in a form like this
<form …>
<input id="x" type="hidden" name="content">
<trix-editor input="x"></trix-editor>
</form>
you can get the value in the controller like this
$text = request()->input('content');
// and then save it into db
Text_box::create([
//your other fields
'text' => $text,
]);
I'm trying to save an image from a form into database. I tried this but it's not working:
public function store(Request $request)
{
$article = new article;
$photo_articles = new photo_articles;
// $type = new type;
$article->NOM_ARTICLE = $request->NOM_ARTICLE;
$article->DESCRIPTION_ARTICLE = $request->DESCRIPTION_ARTICLE;
$article->id = auth()->user()->id;
$article->TYPE_ARTICLE = $request->LABEL_TYPE;
$article->save();
$photo_articles->PHOTO_ARTICLE = base64_encode(file_get_contents($request->PHOTO_ARTICLE));
$photo_articles->ID_ARTICLE = $article->ID_ARTICLE;
$photo_articles->save();
return;
}
Here is my form:
<form method="post" action="{{ route('addarticle.store') }}" class="contact_form text-center" id="contact_form">
{{ csrf_field() }}
<div class="row">
<div class="col-lg-6">
<div class="col-lg-12">
<input type="text" class="contact_input" name="NOM_ARTICLE" placeholder="Nom d'article"
required="required">
</div>
<div class="col-lg-12">
<select class="contact_input" name="LABEL_TYPE">
#foreach($types as $type)
<option> {{$type->LABEL_TYPE}}</option>
#endforeach
</select>
</div>
</div>
<div class="col-lg-6">
<div id="uploading" class="uploadfile">
<input type="hidden" name="MAX_FILE_SIZE" value="250000"/>
<input type="file" class="contact_input uploadFileInput" id="imagearticle" name="PHOTO_ARTICLE"
placeholder="Capture de votre article" name="fic" size=50 required="required"/>
<p id="uploadtextid" class="uploadText">upload image</p>
<img class="uploadImage" src="" id="displayedimage">
</div>
</div>
<div class="col-lg-12">
<textarea class="contact_textarea contact_input" name="DESCRIPTION_ARTICLE" placeholder="Description"
required="required"></textarea>
</div>
<button class="contact_button right" type="submit">Valider!</button>
</div>
</form>
My image is in $request->PHOTO_ARTICLE.
Can someone show me how to save it as base64? I've searched a lot but without result.
When you're submitting a file with a form you have to set add the attribute
enctype="multipart/form-data" to the opening form tag:
<form enctype="multipart/form-data" method="post" action="{{ route('addarticle.store') }}" class="contact_form text-center" id="contact_form">
otherwise it will only submit the name of the file and not the file itself.
Then in your route you would just need:
$photo_articles->PHOTO_ARTICLE = base64_encode(
file_get_contents($request->file('PHOTO_ARTICLE')->path())
);
I have the following problem when trying to edit an "album", hopefully they can help me, I'm a little frustrated haha.
The Form
<form name="editalbum" action="{{ action('AlbumController#postEdit', $album->id) }}" method="POST" enctype="multipart/form-data">
{{ csrf_field() }}
<fieldset>
<h2>Editar <strong>{{$album->name}}</strong></h2>
<br></br>
<div class="form-group">
<label for="name">Nombre del proyecto</label>
<input name="name" type="text" class="form-control" value="{{ $album->name }}" required>
</div>
<div class="form-group">
<label for="description">Descripción del proyecto</label>
<textarea name="description" rows="10" cols="50" type="text" class="form-control" value="{{ $album->description }}" required></textarea>
</div>
<div class="form-group">
<label for="location">Locación:</label>
<input name="location" type="text" class="form-control" value="{{ $album->location }}" required>
</div>
<div class="form-group">
<label for="year">Año:</label>
<input name="year" type="text" class="form-control" value="{{ $album->year }}" required>
</div>
<button type="submit" class="btn btn-primary">Editar</button>
</fieldset>
</form>
So far I think everything is going well because I try to post in the ID of the model.
The function:
public function postEdit(Request $request, $id)
{
$album = Album::find($id);
$album = Album::all();
if(count($album) > 0){
$album->name = Input::get('name');
$album->description = Input::get('description');
$album->year = Input::get('year');
$album->location = Input::get('location');
$album->save();
Alert::success('Successfully Updated', 'Congratulations');
return view('admin.dashboard');
} else {
Alert::error('Facilities not found', 'Error');
return view('galeries');
}
I think you made error in routes.php
It should look like this:
Route::post('albums/update/{id}', ['uses' => 'AlbumController#postEdit']);
One solution will be to remove the DI Request object
public function postEdit($id)
{
//rest of code
}
note: the param has to be passed as a array
action="{{ action('AlbumController#postEdit', ['id' => $album->id]) }}"