I am trying to add multiple subitems to my eloquent model as arrays but am unable to do so.
View:
<div class="row">
<div class="col-md-6">
<form class="" action="{{route('production.update', $rm->id)}}" method="post">
<input name="_method" type="hidden" value="PATCH">
{{csrf_field()}}
<!-- <input type="hidden" name="product_id" id="product_id" class="form-control" value="{{$rm->id}}"> -->
<div class="form-group{{ ($errors->has('batch_id')) ? $errors->first('title') : '' }}">
<lable>Batch ID</lable>
<input type="text" name="batch_id" id="batch_id" class="form-control" value="{{$rm->product_id}}" readonly="">
{!! $errors->first('wastage','<p class="help-block">:message</p>') !!}
</div>
<div class="form-group{{ ($errors->has('item_id')) ? $errors->first('title') : '' }}">
<lable>Item Name</lable>
<input type="hidden" name="item_id" id="item_id" class="form-control" value="{{$rm->item_id}}" readonly="">
<input type="text" class="form-control" value="{{$rm->item->item_name}}" readonly="">
{!! $errors->first('wastage','<p class="help-block">:message</p>') !!}
</div>
<div class="form-group{{ ($errors->has('rquantity')) ? $errors->first('title') : '' }}">
<lable>Quantity (Kg)</lable>
<input type="text" name="rquantity" id="rquantity" class="form-control" value="{{$rm->quantity}}" readonly="">
{!! $errors->first('wastage','<p class="help-block">:message</p>') !!}
</div>
<div class="form-group{{ ($errors->has('')) ? $errors->first('title') : '' }}">
<lable>Packing</lable>
#foreach($subitem as $sub)
<div class="row">
<div class="col-md-4">
<input type="checkbox" name="subitem[{{$sub->id}}]['subitem_id']" value="{{$sub->id}}"> {{$sub->subitem_name}}<br><br>
</div>
<div class="col-md-4">
<input type="text" name="subitem[{{$sub->id}}]['qty']" id="qty" class="form-control" placeholder="Entire Qty">
{!! $errors->first('qty','<p class="help-block">:message</p>') !!}
</div>
</div>
#endforeach
</div>
<div class="form-group">
<input type="submit" class="btn btn-primary" value="Add">
</div>
</form>
</div>
</div>
Controller:
public function update(Request $request, $id)
{
$result = Production::findOrFail($id);
foreach($request->subitem as $key=>$row)
{
//print_r($request->subitem);exit;
$items = new Itempacking;
$items->batch_id = $result->product_id;
$items->item_id = $result->item_id;
$items->rquantity = $result->quantity;
$items->product_id = $result->id;
$items->subitem_id = $row['subitem_id'];
$items->qty = $row['qty'];
$items->status = 1;
$items->save();
$items='';
}
}
When I uncomment this line print_r($request->subitem); exit; I can see like this:
Array (
[3] => Array (
['subitem_id'] => 3
['qty'] => 2
)
[4] => Array (
['subitem_id'] => 4
['qty'] => 3
)
)
But when I comment and try to send data to table it is not working. It gives this message
Undefined index: subitem_id
Don't insert '' for key of array in HTML code.You can print your request to details.
Replace from
subitem[{{$sub->id}}]['subitem_id']
subitem[{{$sub->id}}]['qty']
to
subitem[{{$sub->id}}][subitem_id]
subitem[{{$sub->id}}][qty]
Related
I have a search bar with 3 types of input and I want to search into my database if a data exist with those criteria.
Here is my html code for my search bar :
<form method="GET" action="{{ route('admin.liste.article.accueil.article') }}" class="mt-4 background_form">
<div class="form-row justify-content-center">
<div class="form-group col-md-4">
<label for="inputCity">Rechercher par ...</label>
<input class="form-control" name="rechercher" type="text" aria-label="Search" value="{{ request()->query('recherche') }}">
</div>
<div class="form-group col-md-2">
<label for="inputState">Type article</label>
<select id="inputState" class="form-control" name="type_article">
<option></option>
#foreach ($type_articles as $type_article)
<option value="{{ $type_article->type_article_id }}">{{ $type_article->libelle }}</option>
#endforeach
</select>
</div>
<div class="form-group col-md-3">
<label for="datePublication">Date de publicaton</label>
<input class="form-control" type="text" placeholder="Exemple : 2021-02-29" name="date" value="{{ request()->query('date') }}">
</div>
<div class=" col-md-2 align-self-center mt-3">
<button type="submit" class="form-control btn-sm btn-custom mb-2">Trouver</button>
</div>
</div>
</form>
Into my controller :
public function accueil_article(Request $request)
{
$rechercher_par_accueil = $request->query('rechercher');
$type_article_rechercher_accueil = $request->query('type_article');
$date_publication_recherche_accueil = $request->query('date');
if($rechercher_par_accueil || $type_article_rechercher_accueil || $date_publication_recherche_accueil){
$article_rechercher = Article::where('titre', 'like', "%{$rechercher_par_accueil}%")
->when(request()->query('type_article_recherche'), function($query) {
$query->where('type_article_id', 'like', "%{$type_article_rechercher_accueil}%");
})
->when(request()->query('date_publication_recherche'), function($query) {
$query->where('created_at', 'like', "%{$date_publication_recherche_accueil}%");
})
->simplePaginate(5);
} else {
$article_rechercher = Article::orderBy('created_at','desc')->paginate(5);
}
return view('admin/article/admin_liste_article', [
'articles' => $article_rechercher,
'type_articles' => Type_article::all(),
'themes' => Theme::all()
]);
}
And at the bottom of my view, I've :
{!! $articles->appends(['rechercher' => request()->query('rechercher'), 'type_article' => request()->query('type_article'), 'date' => request()->query('date')])->links() !!}
Cordially
Try:
$query->whereIn('type_article_id', [$type_article_rechercher_accueil]);
Hi I am new to laravel and javascript,
I have a multiple input forms for updating of product information including a image upload using Dropzone.js to update product image. However I cant see to update my image file as I keep getting a null value for my dropzone image when I have already dragged a file in.
Below are my codes in the product-edit page:
<form action="{{ route('merchant.product.update', $product->prodID) }}" method="POST" class="dropzone" enctype="multipart/form-data">
{{ csrf_field() }}
{{ method_field('PATCH') }}
<div class="form-group">
<h5>Code</h5>
<input type="text" name="prodCode" class="form-control" id="prodCode" placeholder="Product Code" value="{{ old('prodCode', $product->prodCode) }}" required>
<div class="spacer"></div>
</div>
<div class="form-group">
<h5>Description</h5>
<textarea id="prodDesc" name="prodDesc" class="form-control" id="prodDesc" placeholder="Description" rows="5" required> {{ $product->prodDesc }}</textarea>
<div class="spacer"></div>
</div>
<div class="form-group">
<h5>Price</h5>
<input type="text" name="price" class="form-control" id="price" placeholder="Price" value="{{ old('price', $product->price)}}">
<div class="spacer"></div>
</div>
<div class="form-group">
<h5>Quantity</h5>
<input type="number" name="quantity" class="form-control" id="quantity" placeholder="Quantity" value="{{ old('quantity', $product->quantity)}}">
<div class="spacer"></div>
</div>
<div class="form-group">
<h5>Feature Product</h5>
<div class="switch">
<input type="checkbox" name="featured" class="switch-input" value="1" {{ old('featured', $product->featured=="true") ? 'checked="checked"' : '' }}/>
<div class="circle"></div>
</div>
</div>
<div class="form-group">
<h5>Product Image</h5>
<div id="dropzoneDragArea" class="dz-default dz-message dropzoneDragArea">
<span>Upload Image</span>
</div>
<div class="dropzone-previews"></div>
</div>
<div class="form-group">
<button type="submit" class="btn btn-large btn-primary">Update Product</button>
</div>
<div class="spacer"></div>
</form>
Below are the Javascript portion of the blade.php:
Below are my Controller Methods I have for the update:
public function storeImage(Request $request) {
if($request->file('file')){
// Upload path
$destinationPath = 'img/products/';
// Get File
$image = $request->file('file');
// Get File Name
$imageName = $image->getClientOriginalName();
// Uploading File to given path
$image->move($destinationPath,$imageName);
$product = new Product();
$product->where('prodID', '=', $request->{'prodID'}, 'AND', 'created_by_merchant_id', '=', $this->checkMerchantID())
->update([
'prodImage' => $imageName,
]);
}
}
//update Product details
public function update(Request $request, $prodID)
{
if ($this->isCodeExist($request->{'prodCode'}, $request->{'prodID'})) {
return back()->withErrors('This code already exists!');
}
try{
$db = new Product();
$db->where('prodID', '=', $prodID, 'AND', 'created_by_merchant_id', '=', $this->checkMerchantID())
->update([
'prodCode' => $request->{'prodCode'},
'prodImage' =>$this->storeImage($request),
'prodDesc' => $request->{'prodDesc'},
'price' => $request->{'price'},
'quantity' => $request->{'quantity'},
'featured' => $request->input('featured') ? true : false,
]);
return back()->with('success_message', 'Product updated successfully!');
} catch (\Illuminate\Database\QueryException $ex) {
Log::channel('merchant_error')->error($ex);
return back()->withErrors('There seems to be an error in updating');
}
}
in laravel 5.6 app I have table name as vehicles, then I need update some of table values in VehicleController update function as this,
public function update(Request $request, $id)
{
$vehicle = Vehicle::find($id);
$vehicle->provincename = $request->input('provincename');
$vehicle->districtname = $request->input('districtname');
$vehicle->townname = $request->input('townname');
$vehicle->brandname = $request->input('brandname');
$vehicle->modelname = $request->input('modelname');
$vehicle->modelyear = $request->input('year');
$vehicle->condition = $request->input('condition');
$vehicle->milage = $request->input('milage');
$vehicle->detail = $request->input('data');
$vehicle->price = $request->input('price');
$vehicle->telephone = $request->input('telephone');
$vehicle->categoryname = $request->input('categoryname');
$vehicle->transmission = $request->input('transmission');
$vehicle->fueltype = $request->input('fueltype');
$vehicle->enginecapacity = $request->input('enginecapacity');
$vehicle->user_id = Auth::user()->id;
$vehicle->save();
and edit form action is,
<form method="post" action="{{ route('vehicles.edit', [$vehicles->id]) }}" enctype="multipart/form-data">
and update route is,
Route::post('myads/{id}', [
'uses' => '\App\Http\Controllers\VehicleController#update',
])->name('vehicles.edit');
and controller edit function,
public function edit($id)
{
$vehicles = Vehicle::findOrFail($id);
}
and edit route is,
Route::get('myads/{id}/edit', [
'uses' => '\App\Http\Controllers\VehicleController#edit',
'as'=> 'vehicles.edit'
]);
but when I click update button it did not update values. no any error occurred here only redirect back to edit form. how can fix this problem?
vehicle model
class Vehicle extends Model
{
use Searchable;
protected $guarded = [];
public function searchableAs()
{
return 'categoryname';
}
public function category()
{
return $this->belongsTo(Category::class);
}
public function uploads()
{
return $this->hasMany(Upload::class);
}
public function cars()
{
return $this->hasMany(Car::class);
}
public function vans()
{
return $this->hasMany(Car::class);
}
public function scopePersonal($query)
{
return $query->where('user_id', Auth::user()->id);
}
}
edit form is,
<form method="post" action="{{ route('vehicles.edit', [$vehicles->id]) }}" enctype="multipart/form-data">
{{csrf_field()}}
<div class="form-group{{ $errors->has('provincename') ? ' has-error' : '' }}">
<label for="exampleFormControlSelect1">Province</label>
<select name="provincename" id="provincename" class="form-control input dynamic" data-dependent="districtname" >
<option value="{{$vehicles->provincename}}">{!! $vehicles->provincename !!}</option>
#foreach($town_list as $town)
<option value="{{$town->provincename}}">{{$town->provincename}}</option>
#endforeach
</select>
#if ($errors->has('provincename'))
<span class="help-block">{{ $errors->first('provincename') }}</span>
#endif
</div>
<div class="form-group{{ $errors->has('districtname') ? ' has-error' : '' }}">
<label for="exampleFormControlSelect1">District</label>
<select name="districtname" id="districtname" class="form-control input dynamic" data-dependent="townname" >
<option value="{{$vehicles->districtname}}">{!! $vehicles->districtname !!}</option>
</select>
#if ($errors->has('districtname'))
<span class="help-block">{{ $errors->first('districtname') }}</span>
#endif
</div>
<div class="form-group{{ $errors->has('townname') ? ' has-error' : '' }}">
<label for="exampleFormControlSelect1">Town</label>
<select name="townname" id="townname" class="form-control input">
<option value="{{$vehicles->townname}}">{!! $vehicles->townname !!}</option>
</select>
#if ($errors->has('townname'))
<span class="help-block">{{ $errors->first('townname') }}</span>
#endif
</div>
<!--hidden select box-->
<div class="form-group" style="display: none;">
<label for="exampleFormControlSelect1">Vehicle Category</label>
<select name="categoryname" id="categoryname" class="form-control input dynamic" data-dependent="brandname" >
#foreach($model_list as $model)
<option value="{{$vehicles->categoryname}}">{{$vehicles->categoryname}}</option>
#endforeach
</select>
</div>
<div class="form-group{{ $errors->has('brandname') ? ' has-error' : '' }}">
<label for="exampleFormControlSelect1">Brand</label>
<select name="brandname" id="brandname" class="form-control input dynamic" data-dependent="modelname" >
<option value="{{$vehicles->brandname}}">{!! $vehicles->brandname !!}</option>
</select>
#if ($errors->has('brandname'))
<span class="help-block">{{ $errors->first('brandname') }}</span>
#endif
</div>
<div class="form-group{{ $errors->has('modelname') ? ' has-error' : '' }}">
<label for="exampleFormControlSelect1">Model</label>
<select name="modelname" id="modelname" class="form-control input">
<option value="{{$vehicles->modelname}}">{!! $vehicles->modelname !!}</option>
</select>
#if ($errors->has('modelname'))
<span class="help-block">{{ $errors->first('modelname') }}</span>
#endif
</div>
<div class="form-group{{ $errors->has('year') ? ' has-error' : '' }}">
<label for="formGroupExampleInput">Model Year</label>
<input type="text" class="form-control" id="year" placeholder="Year" name="year" value="{!! $vehicles->modelyear ?: '' !!}">
#if ($errors->has('year'))
<span class="help-block">{{ $errors->first('year') }}</span>
#endif
</div>
<div class="form-group{{ $errors->has('condition') ? ' has-error' : '' }}">
<label for="formGroupExampleInput">Condition</label>
<label class="radio-inline"><input type="radio" name="condition" value="used" #if($vehicles->condition == 'used') checked #endif>Used</label>
<label class="radio-inline"><input type="radio" name="condition" value="recondition" #if($vehicles->condition == 'recondition') checked #endif>Recondition</label>
<label class="radio-inline"><input type="radio" name="condition" value="new" #if($vehicles->condition == 'new') checked #endif> New</label>
#if ($errors->has('condition'))
<span class="help-block">{{ $errors->first('condition') }}</span>
#endif
</div>
<div class="form-group{{ $errors->has('milage') ? ' has-error' : '' }}">
<label for="formGroupExampleInput">Milage</label>
<input type="text" class="form-control" id="milage" placeholder="Milage" name="milage" value="{!! $vehicles->milage ?: '' !!}">
#if ($errors->has('milage'))
<span class="help-block">{{ $errors->first('milage') }}</span>
#endif
</div>
<div class="form-group{{ $errors->has('transmission') ? ' has-error' : '' }}">
<label for="exampleFormControlSelect1">Transmission</label>
<select class="form-control" id="transmission" name="transmission">
<option value="{!! $vehicles->transmission !!}">{!! $vehicles->transmission !!}</option>
<option value="Manual">Manual</option>
<option value="Auto">Auto</option>
<option value="Hybrid">Hybrid</option>
<option value="Electric">Electric</option>
<option value="Codak">codak</option>
</select>
#if ($errors->has('transmission'))
<span class="help-block">{{ $errors->first('transmission') }}</span>
#endif
</div>
<div class="form-group{{ $errors->has('fueltype') ? ' has-error' : '' }}">
<label for="exampleFormControlSelect1">Fuel Type</label>
<select class="form-control" id="fueltype" name="fueltype">
<option value="{!! $vehicles->fueltype !!}">{!! $vehicles->fueltype !!}</option>
<option value="Petrol">Petrol</option>
<option value="Diesel">Diesel</option>
<option value="Hybrid">Hybrid</option>
<option value="Electric">Electric</option>
</select>
#if ($errors->has('fueltype'))
<span class="help-block">{{ $errors->first('fueltype') }}</span>
#endif
</div>
<div class="form-group{{ $errors->has('enginecapacity') ? ' has-error' : '' }}">
<label for="formGroupExampleInput">Engine capacity</label>
<input type="text" class="form-control" id="enginecapacity" placeholder="Engine capacity" name="enginecapacity" value="{!! $vehicles->enginecapacity ?: '' !!}" >
#if ($errors->has('enginecapacity'))
<span class="help-block">{{ $errors->first('enginecapacity') }}</span>
#endif
</div>
<div class="form-group{{ $errors->has('data') ? ' has-error' : '' }}">
<label for="comment">More Details</label>
<textarea class="form-control" rows="5" id="data" name="data" rows="10" cols="10">{!! trim($vehicles->detail) !!}</textarea>
#if ($errors->has('data'))
<span class="help-block">{{ $errors->first('data') }}</span>
#endif
</div >
<div class="form-group{{ $errors->has('price') ? ' has-error' : '' }}">
<label for="formGroupExampleInput">Price</label>
<input type="text" class="form-control" id="price" placeholder="Price" name="price" value="{!! $vehicles->price ?: '' !!}">
#if ($errors->has('price'))
<span class="help-block">{{ $errors->first('price') }}</span>
#endif
</div>
<div class="form-group{{ $errors->has('telephone') ? ' has-error' : '' }}">
<label for="formGroupExampleInput">Telephone</label>
<input type="text" class="form-control" id="telephone" placeholder="Telephone" name="telephone" value="{!! $vehicles->telephone ?: '' !!}" >
#if ($errors->has('telephone'))
<span class="help-block">{{ $errors->first('telephone') }}</span>
#endif
</div>
<!-- <button type="submit" class="btn btn-primary" style="margin-top:10px">Submit</button>
</div> -->
#if( $vehicles->uploads->count() > 0 )
#php
$upload = $vehicles->uploads->sortByDesc('id')->first();
#endphp
<!-- <img id="preview" src="/images/{{ $upload->resized_name }}"> -->
<!--edit/delete buttons-->
#foreach( $vehicles-> uploads as $upload)
<img id="preview"
src="{{asset((isset($upload) && $upload->resized_name!='')?'images/'.$upload->resized_name:'images/noimage.png')}}"
height="200px" width="200px"/>
<input class="form-control" style="display:none" name="files[]" type="file" id="files" name="_token" value="{{ csrf_token() }}" enctype="multipart/form-data">
<br/>
<!-- Add Image | -->
<!-- <a style="color: red" href="javascript:removeImage()">Delete</a>
<input type="hidden" style="display: none" value="0" name="remove" id="remove"> -->
Edit Image|
<a class="button is-outlined" href="/myads/{{$upload->id}}/delete" onclick="return confirm('Are you sure to want to delete this record?')" >Delete</a></td>
<hr>
#endforeach
#endif
<button type="submit" class="btn btn-primary" style="margin-top:10px">Submit</button>
</div>
There will be mutiple reasons
1. You are not passing the csrf token with form request.
2. There will be one or more input value missing and you have not show the error message in the validation.
3. Vehicle id not exist.
etc.
try this way
and remove or comment this lines below
//$vehicle->save();
$vehicle = array('provincename'=>$request->input('provincename'),
'districtname' => $request->input('districtname'),
'townname' => $request->input('townname'),
'brandname' => $request->input('brandname'),
'modelname' => $request->input('modelname'),
'modelyear' => $request->input('year'),
'condition' => $request->input('condition'),
'milage' => $request->input('milage'),
'detail' => $request->input('data'),
'price' => $request->input('price'),
'telephone' => $request->input('telephone'),
'categoryname' => $request->input('categoryname'),
'transmission' => $request->input('transmission'),
'fueltype' => $request->input('fueltype'),
'enginecapacity' => $request->input('enginecapacity'),
'user_id' => Auth::user()->id);
Vehicle::where('id', $id)->update($vehicle);
You can use array to update your record and also make sure to pass csrf token when submitting a data. Add user_id column to the array.
DB::table('vehicles')
->where('id', $vehicle)
->update(['provincename ' => $request->input('provincename'),
'districtname'=>$request->input('districtname'),
'townname' =>input('townname'), 'user_id'=>Auth::user()->id ]);
I'm new to Laravel. I want to check if there is an ID of the selected item and user from my form. Both these fields are in my item_assignments table. Whenever there is no ID found, it will create a new assignment and store it to the item_assignments table. This works but when there is an ID found, it should update the existing one by incrementing the count inputted.
Here is my view.
<form class="form-horizontal" method="post" action="{{url('item/assign')}}" enctype="multipart/form-data">
<input type="hidden" name="_token" value="{{ csrf_token() }}" >
<legend>Assign Item</legend>
<fieldset>
<input id="eid" name="id" type="hidden">
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="name">Item Name:</label>
<div class="col-md-6">
<input id="ename" name="name" type="text" class="form-control input-md" readonly>
</div>
</div>
<!-- Select Basic -->
<div class="form-group{{ $errors->has('user') ? ' has-error' : '' }}">
<label class="col-md-4 control-label" for="user">Assign to:</label>
<div class="col-md-6">
<select id="user" name="user" class="form-control">
<option value="0">Select a User</option>
#foreach($users as $user)
<option value="{{$user->id}}">{{$user->name}}</option>
#endforeach
</select>
#if ($errors->has('user'))
<span class="help-block">
<strong>{{ $errors->first('user') }}</strong>
</span>
#endif
</div>
</div>
<!-- Text input-->
<div class="form-group{{ $errors->has('count') ? ' has-error' : '' }}">
<label class="col-md-4 control-label" for="count">Item Count:</label>
<div class="col-md-6">
<input id="count" name="count" type="text" placeholder="Enter Item Count" class="form-control input-md">
#if ($errors->has('count'))
<span class="help-block">
<strong>{{ $errors->first('count') }}</strong>
</span>
#endif
</div>
</div>
<!-- Button (Double) -->
<div class="form-group">
<label class="col-md-5 control-label" for="submit"></label>
<div class="col-md-7">
<button id="submit" name="submit" class="btn btn-success">Assign</button>
</div>
</div>
</form>
This is my controller
// checks the ID of the selected item
$assign1 = ItemAssign::where("item_id", $req->id)->where('user_id', $req->user)->first();
// this works
if (!($assign1)) {
$assign = new ItemAssign();
$assign->user_id = $req->user;
$assign->item_id = $req->id;
$assign->item_count = $req->count;
$assign->balance = $req->count;
$assign->save();
}
// this is what I want to work
else {
$assign = ItemAssign::find($assign1);
$assign->item_count += $req->count;
$assign->balance += $req->count;
$assign->save();
}
// stores to user table
$user = User::find($req->user);
$user->received += $req->count;
$user->save();
// stores to item table
$item = Item::find($req->id);
$count = $item->item_count;
$item->assigned_count += $req->count;
$item->remaining = $count - $item->assigned_count;
$item->save();
return redirect('assignment');
If you already have an instance of ItemAssign stored in $assign1 you should be able to just update that one instead of using a find.
IE:
else {
$assign1->item_count += $req->count;
$assign1->balance += $req->count;
$assign1->update();
}
else {
$assign = ItemAssign::find($assign1);
$assign->item_count += $req->count;
$assign->balance += $req->count;
$assign->update();
}
I am not sure why I am getting this error. Here is the method in the ClientController.
protected function updateOneStudent($parameters)
{
$studentId = $parameters['id'];
return $this- >performPutRequest("https://lumenapi.juandmegon.com/students/{$studentId}", $parameters);
}
Basically I am trying to update a selected student. Below is the update form.
#extends('layouts.master')
#section('content')
<form action="{{url('/student/update')}}" method="POST" role="form">
{{ csrf_field() }}
{{method_field('PUT')}}
<legend>Create a Student</legend>
<div class="form-group">
<label for="">Name</label>
<input type="text" class="form-control" name="name" value="{{$student->name }}"required="required">
</div>
<div class="form-group">
<label for="">Address</label>
<input type="text" class="form-control" name="address" value="{{$student->address }}" required="required">
</div>
<div class="form-group">
<label for="">Phone</label>
<input type="text" class="form-control" name="phone" value="{{$student->phone }}" required="required">
</div>
<div class="form-group">
<label for="">Career</label>
<select name="career" class="form-control" required="required">
<option>Select a Career</option>
<option value="math"{{$student->career == 'math' ? 'selected' : ''}}>Math</option>
<option value="physics"{{$student->career == 'physics' ? 'selected' : ''}}>Physics</option>
<option value="engineering"{{$student->career == '' ? 'engineering' : ''}}>Engineering</option>
</select>
</div>
<button type="submit" class="btn btn-primary">Update Student</button>
</form>
#endsection
The request I was sending was wrong. The error was in the StudentController.
I had
public function getUpdateStudent()
{
$students = $this->obtainAllStudents;
return view('students.select-student', ['students'=> $students]);
}
It it should have been
public function getUpdateStudent()
{
$students = $this->obtainAllStudents();
return view('students.select-student', ['students'=> $students]);
}
I missed the brackets to call the getUpdateStudent. Sorry guys I did not show this code earlier.