Ниже мой файл контроллера ServiceProviderController. php - контроллер
Что я делаю не так в этом случае?
Я получаю ошибку ниже:
exception: "Symfony\Component\HttpKernel\Exception\HttpException", file:
"C:\xampp\htdocs\laundry_admin\vendor\laravel\framework\src\Illumi
<?php
namespace App\Http\Controllers;
use App\ServiceProvider;
use Illuminate\Http\Request;
use DB;
class ServiceProviderController extends Controller
{
public function store(Request $request )
{
$sp = new ServiceProvider;
$sp->shop_name = $request->input('spname');
$sp->mobile_number = $request->input('spmobile');
$sp->shop_address = $request->input('spaddress');
// $sp->shop_image = $request->input('splogo');
$sp->latitude = $request->input('splatitude');
$sp->longitude = $request->input('splongitude');
$sp->rating = $request->input('sprating');
$sp->delivery_days = $request->input('spdeliverydays');
if ($request->hasFile('image')) {
// Let's do everything here
if ($request->file('image')->isValid()) {
//
$validated = $request->validate([
'name' => 'string|max:40',
'image' => 'mimes:jpeg,png|max:1014',
]);
$extension = $request->image->extension();
$request->image->storeAs('/public/images', $validated['name'].".".$extension);
$url = Storage::url($validated['name'].".".$extension);
$sp->shop_image = $url;
$file = File::create([
'name' => $validated['name'],
'url' => $url,
]);
Session::flash('success', "Success!");
return \Redirect::back();
}
}
abort(500, 'Could not upload image :(');
$sp->save();
// return redirect('home')->with('success','Customer added successfully');
}
}
Ниже мой ServiceProvider. php Класс модели
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class ServiceProvider extends Model
{
public $timestamps = false;
protected $table = 'service_provider';
protected $fillable = [
'shop_name',
'mobile_number',
'shop_address',
'shop_image',
'latitude',
'longitude',
'rating',
'delivery_days'
];
}
Ниже мой файл лезвия service_provider.blade. php - файл лезвия
<!-- Modal -->
<div class="modal fade" id="add" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Add Service Provider</h5>
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<div class="modal-body">
<form class="" id="addform">
<div class="position-relative form-group row">
<div class="col-md-3 my-auto text-center">
<label for="spname" class="">Shop Name</label>
</div>
<div class="col-md-8">
<input id="spname" placeholder="Name" type="name" name="spname" class="form-control">
</div>
</div>
<div class="position-relative form-group row">
<div class="col-md-3 my-auto text-center">
<label for="spmobile" class="">Mobile No.</label>
</div>
<div class="col-md-8">
<input id="spmobile" placeholder="Mobile No." type="number" name="spmobile" class="form-control">
</div>
</div>
<div class="position-relative form-group row">
<div class="col-md-3 my-auto text-center">
<label for="splatitude" class="">Latitude.</label>
</div>
<div class="col-md-8">
<input id="splatitude" type="number" name="splatitude" class="form-control">
</div>
</div>
<div class="position-relative form-group row">
<div class="col-md-3 my-auto text-center">
<label for="splongitude" class="">Longitude.</label>
</div>
<div class="col-md-8">
<input id="splongitude" type="number" name="splongitude" class="form-control">
</div>
</div>
<div class="position-relative form-group row">
<div class="col-md-3 my-auto text-center">
<label for="spaddress" class="">Shop Address</label>
</div>
<div class="col-md-9">
<textarea id="spaddress" name="spaddress" class="form-control"></textarea>
</div>
</div>
<div class="position-relative form-group row">
<div class="col-md-3 my-auto text-center">
<label for="image" class="">logo</label>
</div>
<div class="col-md-8">
<input id="image" type="file" name="image" class="form-control-file">
</div>
</div>
<div class="position-relative form-group row">
<div class="col-md-3 my-auto text-center">
<label for="sprating" class="">Rating.</label>
</div>
<div class="col-md-8">
<input id="sprating" type="number" name="sprating" class="form-control">
</div>
</div>
<div class="position-relative form-group row">
<div class="col-md-3 my-auto text-center">
<label for="spdeliverydays" class="">Delivery Days.</label>
</div>
<div class="col-md-8">
<input id="spdeliverydays" type="number" name="spdeliverydays" class="form-control">
</div>
</div>
<div class="position-relative form-group row">
<div class="col-md-3 my-auto text-center">
<label for="exampleaddress" class="">Services</label>
</div>
<div class="col-md-9">
<div class="row">
<div class="col-sm-12 col-md-6 mt-3 text-center">
<label for="exampleaddress" class="mr-2">Dry Clean</label>
<input type="checkbox" checked data-toggle="toggle" data-onstyle="success">
</div>
<div class="col-sm-12 col-md-6 mt-3 text-center">
<label for="exampleaddress" class="mr-2">Wash & Fold</label>
<input type="checkbox" checked data-toggle="toggle" data-onstyle="success">
</div>
<div class="col-sm-12 col-md-6 mt-3 text-center">
<label for="exampleaddress" class="mr-2">Wash & Iron</label>
<input type="checkbox" checked data-toggle="toggle" data-onstyle="success">
</div>
<div class="col-sm-12 col-md-6 mt-3 text-center">
<label for="exampleaddress" class="mr-2">Stream Press</label>
<input type="checkbox" checked data-toggle="toggle" data-onstyle="success">
</div>
</div>
</div>
</div>
<div class="text-center">
<button type="submit" id="addserviceprovider" class="mt-1 btn-wide btn-pill btn-shadow btn-hover-shine btn btn-primary">Submit
</button>
</div>
</form>
</div>
</div>
</div>
</div>
<script type="text/javascript">
$(document).ready(function(){
$('#addform').on('submit', function(e){
e.preventDefault();
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
$.ajax({
type: "POST",
url: "/add_sp",
data: $('#addform').serialize(),
success: function (response) {
console.log(response)
$('#add').modal('hide')
alert("Service Provider added Successfully");
},
error: function(error){
console.log(error)
alert("Service provider not added");
}
});
});
});
</script>
</html>
Вот мой web. php - файл маршрута
Route::post('/add_sp','ServiceProviderController@store');