how to make a dropdown list only options in relation with the chosen "Metier"? - laravel

I have this form and then I have in my database a set of "taches" that is linked to each "metier", I want to choose a "metier" in the field and the following field "taches" to propose me to choose only "taches" related to this "metier". Here is my code and my form.I would be very grateful if someone could help me with this.
create.blade.php
#extends('Layouts/app')
#extends('Layouts.master')
#section('content')
#if(count($errors))
<link rel="stylesheet"
href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<div class="alert alert-danger" role="alert">
<ul>
#foreach($errors ->all() as $message)
<li>{{$message}}</li>
#endforeach
</ul>
</div>
#endif
<div class="container">
<div class="row">
<div class="col-md-10">
<h1>Tarification tache</h1>
<form action=" {{url ('tarification') }}" method="post">
{{csrf_field()}}
<div class="form-group">
<label for="technicien">Technicien</label>
<select name="technicien_id" id="technicien" class="form-control" >
#foreach($techniciens as $techniciens)
<option value="{{ $techniciens->id }}">
{{$techniciens->id}}
</option>
#endforeach
</select>
</div>
////////////
{{Form::open(array('url'=>'','files'=>true))}}
<div class="form-group">
<label for="metier">Libelle metier</label>
<select name="metier" id="metier" class="form-
control">
#foreach($metiers as $metier)
<option value="{{ $metier->id }}">
{{$metier->libelle_metier}}
</option>
#endforeach
</select>
</div>
<div class="form-group">
<label for="Tache">Libelle Tache</label>
<select name="tache" id="Tache" class="form-control">
#foreach($taches as $tache)
<option value="{{ $tache->id }}">
{{$tache->libelle_tache}}
</option>
#endforeach
</select>
</div>
{{Form::close()}}
//////////////
<div class="form-group">
<label for="">Tarif</label>
<input type="text" name ="Tarif" class="form-control"value="{{old('tarif')}}">
</div>
<div class="form-group">
<input type="submit" value = "enregistrer" class="form-control btn btn-primary">
</div>
</form>
</div>
</div>
<script>
$('#metier').on('change',function(e){
console.long(e);
var met_id = e.target.value;
$.get('/ajax-tac?met_id=' + met_id, function(data){
$('#tache').empty();
$.each(data,function(index, tacObj){
$('#tache').append('<option value="'+tacObj.id+'">'+catObj.libelle_tache+'</option>');
});
});
});
</script>
#endsection
route.php
Route::get('/tarification', 'TarificationController#index');
Route::get('/tarification/create', 'TarificationController#create');
Route::post('/tarification', 'TarificationController#store');
Route::get('/tarification/{id}/edit', 'TarificationController#edit');
Route::put('/tarification/{id}', 'TarificationController#update');
Route::delete('/tarification/{id}', 'TarificationController#destroy');
Route::get('/ajax-metier',function(){
$met_id = Input::get('met_id');
$taches = tache::where('metier_id','=', $met_id)->get();
return Response::json($metiers);
});
controller
public function create()
{
$techniciens = technicien::orderBy('id','desc')->get();
$taches = Tache::orderBy('libelle_tache', 'asc')->get();
$metiers = Metier::all();
return view('tarification.create')->with('taches', $taches)->with('techniciens', $techniciens)->with('metiers', $metiers);
}
/**
* Store a newly created resource in storage.
*
* #param \Illuminate\Http\Request $request
* #return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$tarification = new tarificationtache();
$tarification ->tache_id = $request->input('tache_id');
$tarification ->Tarif =$request->input('Tarif');
$tarification->save();
$tarification->techniciens()->attach($request->technicien_id);
return redirect('home');
}

Related

Laravel Excel import using Maatwebsite Excel package with additional columns from View

I am trying to import data into MySQL from an Excel file. My table has 2 foreign keys project_id and site_id when importing I am selecting these 2 fields from dropdowns in my View. Is there a way I can map these 2 fields to my import collection? Mind you, the 2 fields do not exist in the import file (for integrity reasons) but they do exist in the table.
Collection
namespace App\Imports;
use App\Proposal;
use Maatwebsite\Excel\Concerns\ToModel;
use Maatwebsite\Excel\Concerns\WithHeadingRow;
class ProposalsImport implements ToModel, WithHeadingRow
{
public function model(array $row)
{
return new Proposal([
'building' => $row['building'],
'floor' => $row['floor'],
'area' => $row['area'],
'room' => $row['room'],
'luminaire' => $row['luminaire'],
'actual_qty' => $row['actual_qty'],
'installed_qty' => $row['installed_qty'],
]);
}
}
Controller
public function import()
{
Excel::import(new ProposalsImport, 'proposals.xlsx');
}
View
#extends('projectmanagement/proposals.base')
#section('action-content')
<!-- Main content -->
<section class="content">
<div class="container">
<div class="box">
<div class="box-header">
</div>
<!-- /.box-header -->
<div class="box-body" data-widget="box-refresh">
#if (session('status'))
<div style="padding-top: 0px;padding-bottom: 0px;"
class="alert alert_cust alert-success alert-dismissable fade in">{{ session('status') }}×</div>
#endif
</div>
<div class="row">
<div class="col-lg-12">
<form class="form-horizontal" role="form" method="POST" enctype="multipart/form-data" action="{{ route('proposals.store') }}">
{{ csrf_field() }}
<div class="row">
<div class="col-md-12">
<div class="form-group{{ $errors->has('project_id') ? ' has-error' : '' }}">
<label for="project_id" class="col-md-4 control-label">Project Name</label>
<div class="col-md-6">
<select id="project_id" class="form-control select2" style="width: 100%;"
name="project_id">
<option value="0" disabled selected>Select Project</option>
#foreach ($projects as $project)
<option value="{{$project->id}}">{{ $project->project_name }}</option>
#endforeach
</select>
#if ($errors->has('project_id'))
<span class="help-block">
<strong>{{ $errors->first('project_id') }}</strong>
</span>
#endif
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<br/>
<div class="form-group{{ $errors->has('site_id') ? ' has-error' : '' }}">
<label for="site_id" class="col-md-4 control-label">Site Name</label>
<div class="col-md-6">
<select id="site_id" class="form-control select2" style="width: 100%;"
name="site_id">
<option value="0" disabled selected>Select Site</option>
#foreach ($sites as $site)
<option value="{{$site->id}}">{{ $site->site_name }}</option>
#endforeach
</select>
#if ($errors->has('site_id'))
<span class="help-block">
<strong>{{ $errors->first('site_id') }}</strong>
</span>
#endif
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<br/>
<div class="form-group{{ $errors->has('proposal_file') ? ' has-error' : '' }}">
<label for="proposal_file" class="col-md-4 control-label">Proposal File</label>
<div class="col-md-6">
<input id="proposal_file" type="file" class="form-control" name="proposal_file" required autofocus>
#if ($errors->has('proposal_file'))
<span class="help-block">
<strong>{{ $errors->first('proposal_file') }}</strong>
</span>
#endif
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<br/>
<div class="form-group">
<div class="col-md-4">
</div>
<div class="col-md-6">
<button type="submit" class="btn col-sm-3 col-xs-5 btn-primary">Upload Proposal</button>
</div>
</div>
<br/>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
#push('custom_scripts')
<script>
</script>
#endpush
#endsection
Override import controller's construct method, sending all the parameters you need, like this:
class ProposalsImport implements ToModel, WithHeadingRow
{
protected $project_id;
protected $site_id;
public function __construct($project_id, $site_id)
{
$this->project_id = $project_id;
$this->site_id = $site_id;
}
public function model(array $row)
{
return new Proposal([
'building' => $row['building'],
'project_id' => $this->project_id,
'site_id' => $this->site_id
]);
}
}
And then, call it from your Controller like this:
public function import(Request $request)
{
Excel::import(new ProposalsImport($request->project_id, $request->site_id), 'proposals.xlsx');
}

Using Select in an Edit Form Laravel

Im trying to implement a Edit function to update permissions from an Laravel User, (I already installed Spatie), it parcially works, it save the changes but I cant see the permissions of the role on the Select Form. Any help please
<--CONTROLLER-->
public function edit($id)
{
$role = Role::findById($id);
$permissions = Permission::all();
return view('admin_roles_edit', compact('role','permissions', 'permissions1'));
}
public function update(Request $request, $id)
{
$request->validate([
'name'=>'required|max:30',
]);
$role = Role::findById($id);
$role->update($request->all());
$role->permissions()->sync($request->permissions);
return redirect()->route('admin.roles.index')->with('message', 'El rol se ha actualizado correctamente');
}
<--HTML-->
<form action="{{route('admin.roles.update', $role->id)}}" method="post"
class="form">
#csrf
<div class="form-group has-feedback">
<label class="control-label col-lg-3">Nombre<span
class="text-danger">*</span></label>
<input type="text" class="form-control" name="name"
value="{{$role->name}}" required="required">
#error('name')
<label class="validation-error-label" for="basic">{{$message}}</label>
#enderror
</div>
<div class="form-group has-feedback">
<label class="control-label col-lg-3">Permisos<span
class="text-danger">*</span></label>
<div class="multi-select-full">
<select class="multiselect" multiple="multiple" name="roles">
#foreach($permissions as $permission)
<option value="{{$permission->id}} #if($permission->id == $role->permission) selected #endif">{{$permission->name}}</option>
#endforeach
</select>
</div>
</div>
<div class="form-group pull-right">
<a href="{{route('admin.roles.index')}}" type="button" class="btn btn-default"><i
class="icon-cross2 position-left"></i>Cancelar
</a>
<button type="submit" class="submit-btn btn btn-success"><i
class="icon-add position-left"></i>Editar
</button>
</div>
</form>
<--RESULT-->
in your controller add this line:
public function edit($id)
{
$role = Role::findById($id);
$permissions = Permission::all();
$rolePermissions = $role->permissions()->pluck('name','id')->toArray();
return view('admin_roles_edit', compact('role','permissions', 'rolePermissions'));
}
update your blade:
<option value="{{$permission->id}}" {{in_array($permission->id, array_keys($rolePermissions)) ? 'selected' : '')}}>{{$permission->name}}</option>
Fixed finally
RoleController.php
public function edit($id)
{
$role = Role::findById($id);
$permissions = Permission::all();
return view('admin_roles_edit', compact('role','permissions'));
}
RoleView.blade.php
<select class="multiselect" multiple="multiple" name="roles">
#foreach($permissions as $permission)
<option value="{{$permission->id}}"
#if($role->hasPermissionTo($permission->id))
selected="selected"
#endif/>{{$permission->name}}</option>
#endforeach
</select>
Fixed Result

Hidden type input value not being passed in Laravel gallery Project

I have created an album. I am trying to upload photos to the album and storing the album_id through the 'hidden' type input. When i check the source code, album_id is shown in 'value' attribute but unfortunately the value is not being passed to the query during form submission.
My create method of PhotoController which shows the form
public function create($id)
{
$albums = Album::where('id',$id)->first();
return view('admin.pages.photos',compact('albums', 'id'));
}
Here is the form.
<div class="container">
<div class="row">
<a class="btn btn-success" href="/gallery/{{$albums->slug}}">Back to Gallery</a>
<h4>Upload Photos to <strong>{{$albums-> name}}</strong> Gallery</h4>
#if (session('status'))
<div class="alert alert-success">
{{ session('status') }}
</div>
#endif
<img class="thumbnail" src="/images/gallery/{{$albums->cover_pic}}" alt="{{$albums->name}}">
</div>
<div class="col-md-8">
<form class="form-horizontal" action="/photo" method="POST" enctype="multipart/form-data" >
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<div class="form-group">
<label class="col-md-8">Photo Title:</label>
<input type="text" name="photo_name" class="form-control" placeholder="Name of the Photo" value="{{ old('photo_name') }}" >
</div>
<div class="form-group">
<label class="col-md-8">Description</label>
<input type="text" name="desc" class="form-control" placeholder="Write Description" value="{{ old('desc') }}">
</div>
<div class="form-group">
<label class="col-md-8">Upload Pic</label>
<input type="file" name="photo" class="form-control" value="{{old('photo')}}" >
</div>
<input type="hidden" name="album_id" value="{{$albums->id}}">
<button type="submit" name="submit" class="btn btn-success waves-effect waves-light m-r-10">Submit</button>
</form>
and the store method
public function store(Request $request)
{
$this->validate($request, [
'photo_name'=>'required|min:3',
'desc'=>'required',
'photo'=>'required'
]);
$photo = new Photo;
$photo->album_id = $request->album_id;
$photo->photo_name = $request->photo_name;
$str = strtolower($request->photo_name);
$photo->slug = preg_replace('/\s+/', '-', $str);
if($file=$request->file('photo')){
$name = time().'.'.$file->getClientOriginalName();
$file->move('images/gallery', $name);
$photo['photo'] = $name;
}
$photo->desc = $request->desc;
$photo->save();
return redirect()->back()->with('status', 'Photo Successfully Added!');
}

Laravel pass id from blade template to store controller

I am trying to pass id to store controller as I need to save business_id that is being retrieved from another table. However I get:
Missing argument 2 for App\Http\Controllers\EventController::store()
Here's my view:
#extends('master') #section('title', 'Live Oldham')
#section('content')
<div class="col-lg-y col-lg-offset-3">
<ul class="list-group-list">
#foreach ($business->businesses as $business)
<li class="list-group-item">
<a target="_blank" href="{{ url('business/' . $business->id) }}"> {{($business->name) }}</a>
</li>
#endforeach
</ul>
</div>
#endsection
Controller:
class EventController extends Controller
{
/**
* Display a listing of the resource.
*
* #return \Illuminate\Http\Response
*/
public function index()
{
$id = Auth::id();
$business = User::where('id', $id)
->with('businesses')
->first();
return view('events.viewEvent', compact('business'));
}
/**
* Show the form for creating a new resource.
*
* #return \Illuminate\Http\Response
*/
public function create($id)
{
return view('events.addEvent')
->with('Business', Business::find($id));
}
/**
* Store a newly created resource in storage.
*
* #param \Illuminate\Http\Request $request
* #return \Illuminate\Http\Response
*/
public function store(Request $request, $id)
{
$event = new Event;
$event->startdate = $request->input('startdate');
$event->enddate = $request->input('enddate');
$event->title = $request->input('title');
$event->frequency = $request->input('frequency');
$event->description = $request->input('description');
$event->business_id = $id;
$event->save();
}
form:
#extends('master') #section('title', 'Live Oldham')
#section('content')
<div class="container">
<!-- Alert Messages -->
#if (session('message'))
#if (session('message')=="success")
<div class="alert alert-success">
Event Created
</div>
#else
<div class="alert alert-danger">
There has been a fatal error! Apologies, we are working to fix it!
</div>
#endif
#endif
<!-- JQuery UI init -->
<script>
$( function() {
$( document ).tooltip();
} );
</script>
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="panel panel-default">
<div class="panel-heading">Create Event</div>
<div class="panel-body">
<form class="form-horizontal" role="form" method="POST" action="{{ action('EventController#store') }}">
{{ csrf_field() }}
<div class="form-group{{ $errors->has('title') ? ' has-error' : '' }}">
<div style="display:none;" class="title_message form-control alert-warning"></div>
<label for="title" class="col-md-4 control-label">Event Title</label>
<div class="col-md-6">
<input id="title" type="text" class="form-control" placeholder="Event title"
title="What is the event title?" name="title" value="{{ old('title') }}">
#if ($errors->has('title'))
<span class="help-block">
<strong>{{ $errors->first('title') }}</strong>
</span>
#endif
</div>
</div>
<div class="form-group{{ $errors->has('frequency') ? ' has-error' : '' }}">
<div style="display:none ;" class="frequency_message form-control alert-warning"></div>
<label id="frequency2" for="frequency" class="col-md-4 control-label">Frequency</label>
<div class="col-md-6">
<select class="form-control" name="frequency" id="frequency">
<option selected disabled>Choose event frequency...</option>
<option value="One">One-time Event</option>
<option value="Daily">Daily</option>
<option value="Weekly">Weekly</option>
<option value="Monthly">Monthly</option>
<option value="Yearly">Yearly</option>
</select>
#if ($errors->has('frequency'))
<span class="help-block">
<strong>{{ $errors->first('frequency') }}</strong>
</span>
#endif
</div>
</div>
<div class="form-group{{ $errors->has('startdate') ? ' has-error' : '' }}">
<div style="display:none ;" class="startdate_message form-control alert-warning"></div>
<label id="startdate2" for="startdate" class="col-md-4 control-label">Event Start Date</label>
<div class="col-md-6">
<input id="startdate" type="date" class="form-control" placeholder="Start Date"
title="When does the event start?" name="startdate" value="{{ old('startdate') }}">
#if ($errors->has('startdate'))
<span class="help-block">
<strong>{{ $errors->first('email') }}</strong>
</span>
#endif
</div>
</div>
<div class="form-group{{ $errors->has('enddate') ? ' has-error' : '' }}">
<div style="display:none ;" class="enddate_message form-control alert-warning"></div>
<label id="address3" for="enddate" class="col-md-4 control-label">Event End Date</label>
<div class="col-md-6">
<input id="enddate" type="date" class="form-control" placeholder="End Date"
title="When does the event end?" name="enddate" value="{{ old('enddate') }}">
#if ($errors->has('enddate'))
<span class="help-block">
<strong>{{ $errors->first('enddate') }}</strong>
</span>
#endif
</div>
</div>
<div class="form-group{{ $errors->has('description') ? ' has-error' : '' }}">
<div style="display:none ;" class="description_message form-control alert-warning"></div>
<label id="description2" for="description" class="col-md-4 control-label">Event Description</label>
<div class="col-md-6">
<textarea id="description" type="text" class="form-control" placeholder="Event description"
title="Here goes event description" name="description" value="{{ old('description') }}">
</textarea>
#if ($errors->has('description'))
<span class="help-block">
<strong>{{ $errors->first('description') }}</strong>
</span>
#endif
</div>
</div>
<div class="form-group">
<div class="col-md-6 col-md-offset-4">
<button type="submit" id="submit" class="btn btn-success">
Add Event
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
#endsection
You can pass the id to the form action
<form method="POST" action="{{ action('EventController#store', $business->id) }}" class="form-horizontal" role="form">
...
</form>

Laravel 5.3 - 500 internal error when saving a new Eloquent model

When trying to create a new instance of my model Apartment I get a 500 (Internal Server Error). I have other /create/ routes that I use to create new instance of my models and they work properly and they're set up same as ApartmentController#create, but for some weird reason it doesn't work.
ApartmentController#create
/**
* Show the form for creating a new resource.
*
* #return \Illuminate\Http\Response
*/
public function create()
{
$addresses = Address::all();
return view('address/create')->with('addresses', $addresses);
}
ApartmentController#store
/**
* Store a newly created resource in storage.
*
* #param \Illuminate\Http\Request $request
* #return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$address = new Address();
$this->authorize('create', $address);
$validator = Validator::make($request->all(), [
'building_number' => 'required|integer',
'street' => 'required|string',
]);
if ($validator->fails()) {
return redirect('addresses/create')
->withErrors($validator)
->withInput();
}
$address->building_number = $request->building_number;
$address->street = $request->street;
$address->save();
return redirect('addresses/create');
}
View apartment/create
<div class="col-md-6">
#if (count($errors) > 0)
<div class="alert alert-danger">
<ul>
#foreach ($errors->all() as $error)
<li>{{ $error }}</li>
#endforeach
</ul>
</div>
#endif
<form class="form-horizontal" method="POST" action="{{ action("ApartmentController#store") }}">
<fieldset>
<!-- Form Name -->
<legend>Register a new apartment</legend>
{{ csrf_field() }}
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="address_id">Address</label>
<div class="col-md-4">
<select id="address_id" name="address_id" class="form-control">
#foreach($addresses as $address)
<option value="{{$address->id}}">{{$address->street}} {{$address->building_number}}</option>
#endforeach
</select>
<span class="help-block">Apartments building number</span>
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="apartment_number">Apartment Number</label>
<div class="col-md-4">
<input id="apartment_number" name="apartment_number" type="text" placeholder="2402" class="form-control input-md" required="">
<span class="help-block">The apartment number</span>
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="size">Apartment Size</label>
<div class="col-md-4">
<input id="size" name="size" type="text" placeholder="56qm" class="form-control input-md" required="">
<span class="help-block">The size of the apartment in qm</span>
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="living_area_size">Living Area Size</label>
<div class="col-md-4">
<input id="living_area_size" name="living_area_size" type="text" placeholder="23qm" class="form-control input-md" required="">
<span class="help-block">The size of the living area in qm</span>
</div>
</div>
<!-- Select Basic -->
<div class="form-group">
<label class="col-md-4 control-label" for="suitable_for">Suitable For</label>
<div class="col-md-4">
<select id="suitable_for" name="suitable_for" class="form-control">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<span class="help-block">Number of people the apartment is suitable for.</span>
</div>
</div>
<!-- Select Basic -->
<div class="form-group">
<label class="col-md-4 control-label" for="furnished">Furnished</label>
<div class="col-md-4">
<select id="furnished" name="furnished" class="form-control">
<option value="1">Yes</option>
<option value="0">No</option>
</select>
</div>
</div>
<!-- Select Basic -->
<div class="form-group">
<label class="col-md-4 control-label" for="balcony_or_terrace">Balcony or Terrace</label>
<div class="col-md-4">
<select id="balcony_or_terrace" name="balcony_or_terrace" class="form-control">
<option value="none">None</option>
<option value="balcony">Balcony</option>
<option value="terrace">Terrace</option>
</select>
</div>
</div>
<!-- Select Basic -->
<div class="form-group">
<label class="col-md-4 control-label" for="floor">Floor</label>
<div class="col-md-4">
<select id="floor" name="floor" class="form-control">
<option value="ground">Ground</option>
<option value="first">First</option>
<option value="second">Second</option>
<option value="third">Third</option>
</select>
</div>
</div>
<!-- Textarea -->
<div class="form-group">
<label class="col-md-4 control-label" for="description">Description</label>
<div class="col-md-6">
<textarea class="form-control" id="description" name="description"></textarea>
</div>
</div>
<!-- Button -->
<div class="form-group">
<label class="col-md-4 control-label" for="submit"></label>
<div class="col-md-4">
<button id="submit" name="submit" type="submit" class="btn btn-primary">Submit</button>
</div>
</div>
</fieldset>
</form>
</div>
<div class="col-md-4">
<legend>Registered Apartments</legend>
#foreach($apartments as $apartment)
<div class="address">
Apartment {{ $apartment->apartment_number }}
<a href="{{ url('/apartments/' . $apartment->id . '/edit') }}"
onclick="event.preventDefault();
document.getElementById('edit-form-{{$apartment->id}}').submit();">
<button class="btn btn-default">Edit</button>
</a>
<form id="edit-form-{{$apartment->id}}" action="{{ url('/apartments/' . $apartment->id . '/edit') }}" method="GET" style="display: none;">
{{ csrf_field() }}
<input type="hidden" name="address_id" value="{{$apartment->id}}">
</form>
<a href="{{ url('/apartments/' . $apartment->id) }}"
onclick="event.preventDefault();
document.getElementById('delete-form-{{$apartment->id}}').submit();">
<button class="btn btn-warning">Delete</button>
</a>
<form id="delete-form-{{$apartment->id}}" method="POST" action="/apartments/{{$apartment->id}}">
{{ csrf_field() }}
{{ method_field('DELETE') }}
</form>
</div>
<br>
#endforeach
</div>
Route web.php
Route::resource('apartments', 'ApartmentController');
apartments table for Apartment model
I tried to catch the exception on the save() method, but nothing is being caught and I still get redirected to /apartments without any Laravel error just Chroms 500 error page.
This is how I tried to catch the error using dwightwatson/validating:
try{
$apartment = new Apartment();
$apartment->apartment_number = $request->apartment_number;
$apartment->size = $request->size;
$apartment->living_area_size = $request->living_area_size;
$apartment->suitable_for = $request->suitable_for;
$apartment->furnished = $request->furnished;
$apartment->balcony_or_terrace = $request->balcony_or_terrace;
$apartment->floor = $request->floor;
$apartment->description = $request->description;
$apartment->address_id = $request->address_id;
$apartment->saveOrFail();
} catch (ValidationException $e) {
$errors = $e->getErrors();
return redirect()->route('apartments.create')
->withErrors($errors)
->withInput();
}
First of all, you Download Fiddler if you haven't already. Fire it up and then trigger the store method again. Fiddler should tell you a great deal about your request and response:
On the left side, you have a list of requests and on the right, you have statistics and inspectors. Under inspectors tab you will see WebView. Click it and you will see the error generated by Laravel.
As for why it might be failing, check if the references are included properly. e.g:
use App\Address;

Resources