Bonjour,
Voila je rencontre un petit problème avec mon code.
public function store(Request $request)
{
$this->validate($request, [
'datepanne' => 'required|date_format:"Y-m-d H:i:s"',
'machine_id' => 'required|integer',
'car_id' => 'required|integer',
'info_id' => 'required|integer',
'description' => 'required',
"pieces" => "required|array",
"pieces.*" => "required|integer",
'photo_avant' => 'required|image|mimes:jpeg,jpg,png,gif,svg|max:13000',
'photo_apres' => 'required|image|mimes:jpeg,jpg,png,gif,svg|max:13000'
]);
$pieces = Piece::all();
$panne = Auth::user()->panne()->create($request->all());
$panne->pieces()->sync($request->input('pieces', []));
$piecespanneqty = 1;
$datepanneinst = $request->datepanne;
if ($request->hasFile('photo_avant')) {
$fileav = $request->file('photo_avant');
$pathav = $fileav->hashName('reims');
$timenow = Carbon::now()->format('d-m-Y H:i:s');
$imageav = Image::make($fileav)->orientate()
->text($datepanneinst, 400, 100, function($font) {
$font->file(public_path('fonts/fonts.ttf'));
$font->size(24);
$font->color('#f00');
$font->align('center');
$font->valign('top');
});
Storage::put($pathav, (string) $imageav->encode());
$urlav = Storage::disk('do')->url($pathav);
$panne->photo_avant = $urlav;
$panne->save();
}
if ($request->hasFile('photo_apres')) {
$fileap = $request->file('photo_apres');
$pathap = $fileap->hashName('reims');
$timenow = Carbon::now()->format('d-m-Y H:i:s');
$imageap = Image::make($fileap)->orientate()
->text($timenow, 400, 100, function($font) {
$font->file(public_path('fonts/fonts.ttf'));
$font->size(24);
$font->color('#f00');
$font->align('center');
$font->valign('top');
});
Storage::put($pathap, (string) $imageap->encode());
$urlap = Storage::disk('do')->url($pathap);
$panne->photo_apres = $urlap;
$panne->save();
}
foreach ($panne->pieces as $piece) {
$piece->decrement('quantity', $piecespanneqty);
}
Entourez votre code pour bien le mettre en forme
comme vous voyez à la fin de decrement le stock , je souhaiterai en meme temps faire une verification sur la quantité et le stock minimum, et si la quantité est =< que le stock minimum envoyer un email au admin pour commander, si vous avez une piste merci d'avance et bonne fête