SQLSTATE[HY000]: General error: 1364 Field - laravel

public function index()
{
$students = Student::all()->toArray();
return view('student.index', compact('students'));
}
/**
* Show the form for creating a new resource.
*
* #return \Illuminate\Http\Response
*/
public function create()
{
return view('student.create');//
}
/**
* Store a newly created resource in storage.
*
* #param \Illuminate\Http\Request $request
* #return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$this->validate($request, [
'first_name' => 'required',
'last_name' => 'required',
'Age' => 'required',
'Address' => 'required',
'Grade_Level' => 'required',
'mothers_first_name' => 'required',
'mothers_last_name' => 'required',
'mothers_age' => 'required',
'fathers_first_name' => 'required',
'fathers_last_name' => 'required',
'fathers_age' => 'required'
]);
$student = new Student([
'first_name' => $request->get('first_name'),
'last_name' => $request->get('last_name'),
'Age' => $request->get('Age'),
'Address' => $request->get('Address'),
'Grade_Level' => $request->get('Grade_Level'),
'mothers_first_name' => $request->get('mothers_first_name'),
'mothers_last_name' => $request->get('mothers_last_name'),
'mothers_age' => $request->get('mothers_age'),
'fathers_first_name' => $request->get('fathers_first_name'),
'fathers_last_name' => $request->get('fathers_last_name'),
'fathers_age' => $request->get('fathers_age')
]);
$student->save();
return redirect()->route('student.index')->with('success', 'New teacher data successfully added');
}
/**
* Display the specified resource.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function show($id)
{
//
}
/**
* Show the form for editing the specified resource.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function edit($id)
{
$student = Student::find($id);
return view('student.edit', compact('student', 'id'));
}
/**
* Update the specified resource in storage.
*
* #param \Illuminate\Http\Request $request
* #param int $id
* #return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
$this->validate($request, [
'first_name' => 'required',
'last_name' => 'required',
'Age' => 'required',
'Address' => 'required',
'Grade_Level' => 'required'
]);
$student = Student::find($id);
$student->first_name = $request->get('first_name');
$student->last_name = $request->get('last_name');
$student->Age = $request->get('Age');
$student->Address = $request->get('Address');
$student->Grade_Level = $request->get('Grade_Level');
$student->save();
return redirect()->route('student.index')->with('success', 'Student data successfully updated');
}
/**
* Remove the specified resource from storage.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function destroy($id)
{
$student = Student::find($id);
$student->delete();
return redirect()->route('student.index')->with('success', 'Data successfully deleted');
}
This is my Controller i dont know why im getting error, i have also other controller with the same function but it works fine. i just recently add this mothers name, age etc part but before it was just name,age address, etc and it works fine but after i add more fillable area's im getting this error
and this is the error im getting
<div class="alert alert-danger">
<button type="button" class="close" data-dismiss="alert">×</button>
<ul>
#foreach($errors->all() as $error)
<li>{{$error}}</li>
#endforeach
</ul>
</div>
#endif
#if(\Session::has('success'))
<div class="alert alert-success">
<button type="button" class="close" data-dismiss="alert">×</button>
<p><strong>{{\Session::get('success')}}</strong></p>
</div>
#endif
<div class="carousel">
<div class="carousel-inner">
<img class="data-img" src="{{asset('img/adddata.png')}}">
</div>
</div>
<div class="container student-create">
<div class="students-info">
<h3>Student's Personal Info</h3>
<form method="post" action="{{url('student')}}">
{{csrf_field()}}
<div class="form-group">
<div class="col-sm">
<label for="Inputfirstname">First Name</label>
<input type="text" class="form-control" name="first_name" placeholder="Enter First Name">
</div>
<div class="col-sm">
<label for="Inputlastname">Last Name</label>
<input type="text" class="form-control" name="last_name" placeholder="Enter Last Name">
</div>
<div class="col-sm">
<label for="Inputlastname">Age</label>
<input type="number" class="form-control" name="Age" placeholder="Enter Last Name">
</div>
</div>
<div class="form-group">
<div class="col-sm">
<label for="InputAddress">Address</label>
<input type="text" class="form-control" name="Address" placeholder="Enter Address">
</div>
<div class="col-sm">
<label for="InputAddress">Grade Level/College Level</label>
<select class="custom-select" name="Grade_Level">
<option selected="">Select Grade Level</option>
<option>Day Care 1</option>
<option>Day Care 2</option>
<option>Kinder Garten 1</option>
<option>Kinder Garten 2</option>
<option>Elementary 1</option>
<option>Elementary 2</option>
<option>Elementary 3</option>
<option>Elementary 4</option>
<option>Elementary 5</option>
<option>Elementary 6</option>
<option>Junior Highschool 1</option>
<option>Junior Highschool 2</option>
<option>Junior Highschool 3</option>
<option>Junior Highschool 4</option>
<option>Senior Highschool 1</option>
<option>Senior Highschool 2</option>
<option>College Level Information Technology 1</option>
<option>College Level Information Technology 2</option>
<option>College Level Information Technology 3</option>
<option>College Level Information Technology 4</option>
</select>
</div>
</div>
<h3>Student's Parents Info</h3>
<div class="form-group">
<div class="col-sm">
<label for="Inputfirstname">Mothers First Name</label>
<input type="text" class="form-control" name="mothers_first_name" placeholder="Enter First Name">
</div>
<div class="col-sm">
<label for="Inputfirstname">Mothers Last Name</label>
<input type="text" class="form-control" name="mothers_last_name" placeholder="Enter Last Name">
</div>
<div class="col-sm">
<label for="Inputfirstname">Mothers Age</label>
<input type="number" class="form-control" name="mothers_age" placeholder="Enter Age">
</div>
</div>
<div class="form-group">
<div class="col-sm">
<label for="Inputfirstname">Fathers First Name</label>
<input type="text" class="form-control" name="fathers_first_name" placeholder="Enter First Name">
</div>
<div class="col-sm">
<label for="Inputfirstname">Fathers Last Name</label>
<input type="text" class="form-control" name="fathers_last_name" placeholder="Enter Last Name">
</div>
<div class="col-sm">
<label for="Inputfirstname">Fathers Age</label>
<input type="number" class="form-control" name="fathers_age" placeholder="Enter Age">
</div>
</div>
<div class="form-group submit">
<button type="button submit" class="btn btn-success">
<i class="fas fa-check"></i> Submit Data
</button>
</div>
</form>
</div>
Table Structure
Student Model
i hope you could help me and Thank in advance

You can change your fathers_age field name to fathers_Age. Because you taken fathers_Age field in your database.

Related

Cannot add data for second time but work for firs time, laravel add user

I'm trying to create a form to insert a user but the function doesn't work the second time, only the first. I got *rror after submitting it a second time.
302 found
UserController
class UserController extends Controller
{
// User
public function edit()
{
return view(
'pages.user.edit',
[
'user' => Auth::user(),
'title' => ''
]
);
}
public function create()
{
return view('pages.user.createUS', [
'levels' => Level::get(),
'perusahaans' => Perusahaan::get(),
'satkers' => Satker::get(),
]);
}
/**
* Create a new user instance after a valid registration.
*
* #param array $data
* #return \App\Models\User
*/
public function store(Request $request)
{
// dd($validatedData);
$this->validate(request(), [
'name' => 'required',
'level_id' => 'required',
'satker_id' => 'required',
'username' => ['required', 'string', 'max:255', 'unique:users'],
'phonenumber' => ['required', 'unique:users'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
]);
$errors = $this->errors();
if ($this->fails()) {
return redirect('users/create')->withErrors($errors)->withInput()->with('err', true);
}
// dd($validatedData, $request);
$user = new User([
'name' => request('name'),
'username' => request('username'),
'email' => request('email'),
'phonenumber' => request('phonenumber'),
'level_id' => request('level_id'),
'satker_id' => request('satker_id'),
'remember_token' => Str::random(10)
]);
$user->password = md5(request('password'));
$user->save();
return redirect()->route('users.create')->with('success', 'User Berhasil Dibuat!');
}
/**
* Indicate that the model's email address should be unverified.
*
* #return static
*/
public function unverified()
{
return $this->state(function (array $attributes) {
return [
'email_verified_at' => null,
];
});
}
public function index()
{
$users = User::latest()->get();
$perusahaans = Perusahaan::get();
$satkers = Satker::latest()->get();
return view(
'pages.user.index',
[
'users' => $users,
'perusahaans' => $perusahaans,
'satkers' => $satkers,
'levels' => Level::get()
]
);
}
public function action(Request $request)
{
$pid = $request->post('pid');
$satkers = Satker::where('perusahaan_id', $pid)->latest()->get();
$html = '<option value="">Pilih Satuan Kerja</option>';
foreach ($satkers as $satker) {
$html .= '<option value="' . $satker->id . '">' . $satker->satker . '</option>';
}
echo $html;
// return response()->json(['html' => $html]);
}
// Setting Profile
public function show(User $user)
{
$details = DetailTransaksi::get();
$transaksis = Transaksi::latest()->get();
$tagihans = Tagihan::latest()->get();
$satkers = Satker::latest()->get();
// dd($tagihans->where('user_id', $user->id));
return view('pages.user.detail', [
'user' => $user,
'transaksis' => $transaksis,
'details' => $details,
'tagihans' => $tagihans,
]);
}
/**
* Update the specified resource in storage.
*
* #param \Illuminate\Http\Request $request
* #param \App\Models\User $user
* #return \Illuminate\Http\Response
*/
public function update(Request $request)
{
$user = Auth::user();
// $file_name = $request->image->getClientOriginalName();
$rules = [
'name' => 'required',
'username' => 'required',
'satker_id' => 'required',
'email' => 'required',
'phonenumber' => 'required',
'level_id' => 'required',
];
if (
$request->email != $user->email
) {
$rules['email'] = 'required|unique:users';
}
$validatedData = $request->validate($rules);
$validatedData['id'] = auth()->user()->id;
User::where('id', $user->id)
->update($validatedData);
return redirect('/user')->with('success', 'Profile has been Updated');
}
}
Blade
<section id="produk-form-create" class="">
<h4 class="fw-bold py-3 mb-4">
<span class="text-muted fw-light">User /</span> Tambah Data User
</h4>
<div class="col-xxl">
<div class="card mb-4">
<div class="card-header d-flex align-items-center justify-content-between">
<h5 class="mb-0">Form Tambah Produk</h5>
</div>
<div class="card-body">
<form action="/users/store" method="POST" enctype="multipart/form-data">
#csrf
<div class="row">
<div class="col-md-6 mb-3 text-start">
<label for="name" class="form-label">Nama User</label>
<input id="name" type="name" name="name" value="{{ old('name') }}"
class="form-control #error('name') is-invalid #enderror" required>
#error('name')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
<div class="col-md-6 mb-3 text-start">
<label for="username" class="form-label">Username</label>
<input id="username" type="text" name="username" value="{{ old('username') }}"
class="form-control #error('username') is-invalid #enderror" required>
#error('username')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
<div class="col-md-6 mb-3 text-start">
<label for="email" class="form-label">Email</label>
<input id="email" name="email" value="{{ old('email') }}" type="text"
class="form-control #error('email') is-invalid #enderror" required>
#error('email')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
<div class="col-md-6 mb-3 text-start">
<label for="leveluser" class="form-label">Level User</label>
<select class="form-select #error('leveluser') is-invalid #enderror" id="leveluser"
name="level_id" required>
#foreach ($levels as $level)
<option value="{{ $level->id }}">{{ $level->level }}</option>
#endforeach
</select>
#error('level_id')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
<div class="col-md-6 mb-3 text-start">
<label class="form-label" for="phonenumber">Phone Number</label>
<div class="input-group input-group-merge">
<span class="input-group-text">ID (+62)</span>
<input type="text" id="phonenumber" name="phonenumber" class="form-control"
placeholder="" value="{{ old('phonenumber') }}" required>
#error('phonenumber')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="col-md-6 mb-3 text-start">
<label for="perusahaan" class="form-label">Perusahaan</label>
<select class="form-select #error('perusahaan_id') is-invalid #enderror" id="perusahaan_id"
name="perusahaan_id" required>
#foreach ($perusahaans as $perusahaan)
<option value="{{ $perusahaan->id }}">{{ $perusahaan->nama_perusahaan }}
</option>
#endforeach
</select>
</div>
<input type="hidden" name="password" id="password" value="12345678">
<div class="col-md-6 mb-3 text-start">
<label for="password" class="form-label">Password</label>
<p>Password default untuk user adalah
<mark><strong
class="text-warning">"12345678"</strong></mark>
mohon arahkan kepada
user untuk mengganti password demi keamanan dan kenyamanan bersama.
</p>
</div>
<div class="col-md-6 mb-3 text-start">
<label for="satker_id" class="form-label">Satuan Kerja</label>
<select id="satker_id" name="satker_id"
class="form-select #error('satker') is-invalid #enderror" required>
#foreach ($satkers->where('perusahaan_id', 1) as $satker)
<option value="{{ $satker->id }}">
{{ $satker->satker }}
</option>
#endforeach
</select>
#error('satker_id')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="row">
<div class="col-sm-4 ">
<button type="submit" class="btn btn-primary"><i class="fw-icons bx bx-send"></i>
Send
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</section>
Routes
Route::get('users', [UserController::class, 'index'])->name('users')->middleware('userlevel');
Route::get('users/{user}/edit', [UserController::class, 'edit'])->name('users.edit')->middleware('userlevel');
Route::get('users/create', [UserController::class, 'create'])->name('users.create')->middleware('userlevel');
Route::post('/users/store', [UserController::class, 'store'])->name('users.store')->middleware('userlevel');
Route::delete('users/{user}/destroy', [UserController::class, 'destroy'])->name('users.destroy')->middleware('userlevel');
Route::put('users/{user}/update', [UserController::class, 'update'])->name('users.destroy')->middleware('userlevel');
Route::post('users/action', [UserController::class, 'action']);
Success in the first-time post but get 302 found in the second time. Please help me to solve this problem.

Laravel: Display of validation errors not shown

I'm having a problem viewing validation errors in the blade view; this is the code below.
Controller (ClientController)
public function store(Request $request) {
$request->validate([
'name' => 'required',
'surname' => 'required',
'diagnosis' => 'required',
]);
Client::create([
'name'=>$request->name,
'surname'=>$request->surname,
'city'=>$request->city,
'diagnosis'=>$request->diagnosis,
]);
return redirect(route('client.index'))->with('message','The customer was successfully saved');
}
View (client.create)
<x-layout>
<div class="container">
#if ($errors->any())
<div class="alert alert-danger">
<ul>
#foreach ($errors->all() as $error)
<li>{{ $error }}</li>
#endforeach
</ul>
</div>
#endif
<form action="{{route('client.store')}}" method="post">
#csrf
<div class="row mt-3">
<div class="col-12 col-md-6">
<div class="mb-3">
<label for="name" class="form-label">Nome</label>
<input type="text" class="form-control p-3" name="name" required>
</div>
<div class="mb-3">
<label for="surname" class="form-label">Cognome</label>
<input type="text" class="form-control p-3" name="surname" required>
</div>
<div class="col-12">
<div class="mb-3">
<label for="diagnosis" class="form-label">Diagnosi</label>
<input type="text" class="form-control p-3" name="diagnosis" required>
</div>
</div>
<button type="submit" class="btn btn-primary mb-5 py-3 px-5 mt-3 ms-3">Add</button>
</div>
</div>
</form>
</div>
</x-layout>
I have followed the documentation but am unable to understand where the problem is.
Laravel documentation
Thanks to those who will help me
CONTROLLER UPDATE:
/**
* Show the form for creating a new resource.
*
* #return \Illuminate\Http\Response
*/
public function create()
{
return view('client.create');
}
/**
* Store a newly created resource in storage.
*
* #param \Illuminate\Http\Request $request
* #return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$request->validate([
'name' => 'required',
'surname' => 'required',
'diagnosis' => 'required',
]);
//dd($request->all());
Client::create([
'name'=>$request->name,
'surname'=>$request->surname,
'city'=>$request->city,
'diagnosis'=>$request->diagnosis,
'stay'=>$request->stay
]);
return redirect(route('client.index'))->with('message','The customer was successfully saved');
}
Index is a blade view that contains the customer table (this works fine).
The problem is the error messages I would like to see in the create view if an input is required and not compiled
So after checking all components, it has been under our nose the whole time.
All your inputs have the required attribute:
<div class="mb-3">
<label for="name" class="form-label">Nome</label>
<input type="text" class="form-control p-3" name="name" required>
</div>
<div class="mb-3">
<label for="surname" class="form-label">Cognome</label>
<input type="text" class="form-control p-3" name="surname" required>
</div>
<div class="col-12">
<div class="mb-3">
<label for="diagnosis" class="form-label">Diagnosi</label>
<input type="text" class="form-control p-3" name="diagnosis" required>
</div>
</div>
This way the request is not sent, because the browser actively needs to fulfil all requirements to start the request to client.create
If you would remove one of these attributes and then not fill it in and submit, it will cause the errors to show.
However, we concluded that it is better to keep the required attribute in, as it is better to prevent a call to the webserver than to only let laravel do the work of validation.
The laravel validation is more useful for ajax/api calls, where there is no frontend to prevent you from making the request, like this:
//required jquery
$.ajax({
url: '/your/url/here',
method: 'POST',
data: [
name: 'somename',
surname: 'somesurname',
],
success(response) {
console.log('Yay, it succeeded')
},
error(error) {
//I havent worked with jquery in a while, the error should be in error object
console.log(error);
}
})
Or how I like to do it in vue, with axios:
//requires axios
axios
.post('/url/here', {
surname: 'somesurname',
diagnosis: 'somediagnosis',
})
.then(response => {
console.log('Yay, it succeeded')
})
.catch(error => {
console.log('Error', error)
})
You can see in the last two examples, as there is no frontend to prevent this request from being made, you now at least make sure laravel is not going to run it's logic with missing variables, which would cause a crash.

Failed to save value select option

what's wrong in my project.
I want to save with select option, but the filed doesn't save data select option. it just save input text.
the project is taken different table, and the form just get the project_name and project_id. project_id will save in in table spent_times.
and the select option will save task_category in table spent_times
this my model
protected $table = 'spent_times';
protected $fillable = [
'task_category',
'story/meeting_name',
'assign',
'estimated_time',
'user_story',
'spent_time',
'percentage',
'lateness',
'index',
'project_id'
];
public function users() {
return $this->hasMany(User::class);
}
public function project() {
return $this->belongsTo(Project::class);
}
my create.blade.php
<form action="{{route('store')}}" method="POST">
#csrf
<div class="box-body">
<div class="form-group">
<label for="">Project *</label>
<select class="form-control select2" style="width: 100%;">
<option>Select One</option>
#foreach($projects as $id => $project)
<option value="{{$id}}">{{$project}}</option>
#endforeach
</select>
</div>
<div class="form-group">
<label for="">Story # Meeting Name *</label>
<input type="text" class="form-control" name="user_story">
</div>
<div class="form-group">
<label for="">Category *</label>
<select class="form-control select2" style="width: 100%;">
<option>Select One</option>
#foreach($task_categories as $category)
<option value="{{$category}}">{{$category}}</option>
#endforeach
</select>
</div>
<div class="form-group">
<label for="">Estimated *</label>
<input type="text" class="form-control" name="estimated_time">
</div>
</div>
<div class="box-footer">
<a href="{{route('index')}}">
<button type="submit" class="btn btn-primary col-md-12" style="border-radius : 0px;">SAVE</button>
</a>
</div>
</form>
my controller
public function create()
{
$spentimes = new SpentTime;
$project = new Project;
$projects = Project::select('project_name', 'id')->get();
return view('Ongoings.index', compact ('projects', 'task_categories', 'spentimes', 'project'));
}
/**
* Store a newly created resource in storage.
*
* #param \Illuminate\Http\Request $request
* #return \Illuminate\Http\Response
*/
public function store(Request $request)
{
dd($request->all());
$spentime = SpentTime::create([
'project_name' => request('project_name'),
'user_stroy' => request ('user_story'),
'task_category' => request('task_category'),
'estimated_time' => request('estimated_time')
]);
$spentime->save();
return redirect()->route('index');
}
error like this
error in web browser
please help me
You are expecting those fields from request in controller.
project_id
meeting_name
task_category
estimated_time
But You are just sending estimated_time,
other 3 fields are not present in you create.blade.php
In create.blade.php, category select input don't have any name.
that's why task_category is getting null from request('task_category'). But task_category field is not nullable in your database table.
Send form input properly as you are expecting in your controller. You can use dd($request->all()) to check.
I believe this is your task_category select box.
so this select box doesn't have a name attribute. that's the error.
Possible solution.
<div class="form-group">
<label for="">Category *</label>
<select name="task_category" class="form-control select2" style="width: 100%;">
<option>Select One</option>
#foreach($task_categories as $category)
<option value="{{$category}}">{{$category}}</option>
#endforeach
</select>
</div>

make certain creation between form and field in database in laravel

want to produce data exclusive to some field in database, so i add them in my view create . but there is an error cannot be null. even though the field is nullable.
this my view form.blade.php
<form action="" method="POST">
#csrf
<div class="box-body">
<div class="form-group">
<label for="">Project *</label>
<select class="form-control select2" style="width: 100%;" name="project_id">
<option>Select One</option>
#foreach($projects as $id => $project)
<option value="{{$id}}">{{$project}}</option>
#endforeach
</select>
</div>
<div class="form-group">
<label for="">Story # Meeting Name *</label>
<input type="text" class="form-control" name="user_story">
</div>
<div class="form-group">
<label for="">Category *</label>
<select class="form-control select2" style="width: 100%;" name="task_category">
<option>Select One</option>
#foreach($task_categories as $task_category)
<option value="{{$task_category->task_category}}">{{$task_category->task_category}}</option>
#endforeach
</select>
</div>
<div class="form-group">
<label for="">Estimated *</label>
<input type="text" class="form-control" name="estimated_time">
</div>
</div>
<div class="box-footer">
<a href="">
<button type="submit" class="btn btn-primary col-md-12" style="border-radius : 0px;">SAVE</button>
</a>
</div>
</form>
this my request
public function rules()
{
return [
'project_id',
'task_category',
'estimated_time',
'spent_time' => 'nullable',
'user_story' => 'nullable',
'story/meeting_name' => 'nullable',
'assign' => 'nullable',
'percentage' => 'nullable',
'lateness' => 'nullable',
'index' => 'nullable',
];
}
this my controller
public function store(OngoingRequest $request)
{
// dd($request->all());
$spentime = SpentTime::create([
'project_id' => request('project_id'),
'user_story' => request ('user_story'),
'task_category' => request('task_category'),
'estimated_time' => request('estimated_time'),
'spent_time' => request('spent_time'),
'assign' => request('assign'),
'story/meeting_name' => request('story/meeting_name'),
'percentage'=> request('percentage'),
'lateness' => request('lateness'),
'index'=> request('index'),
]);
return redirect()->route('plan.index');
}
and the error :
error
fields that i don't want to fill and not in the form must be filled. but im not need that.
set spent_time filed default value other wise set a nullable value
$table->string('spent_time')->nullable();
$table->boolean('spent_time')->default(0);

Laravel View Error

public function index()
{
$students = Student::all()->toArray();
return view('student.index', compact('students'));
}
/**
* Show the form for creating a new resource.
*
* #return \Illuminate\Http\Response
*/
public function create()
{
return view('student.create');//
}
/**
* Store a newly created resource in storage.
*
* #param \Illuminate\Http\Request $request
* #return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$this->validate($request, [
'first_name' => 'required',
'last_name' => 'required',
'Age' => 'required',
'Address' => 'required',
'Grade_Level' => 'required',
'mothers_first_name' => 'required',
'mothers_last_name' => 'required',
'mothers_age' => 'required',
'fathers_first_name' => 'required',
'fathers_last_name' => 'required',
'fathers_age' => 'required'
]);
$student = new Student([
'first_name' => $request->get('first_name'),
'last_name' => $request->get('last_name'),
'Age' => $request->get('Age'),
'Address' => $request->get('Address'),
'Grade_Level' => $request->get('Grade_Level'),
'mothers_first_name' => $request->get('mothers_first_name'),
'mothers_last_name' => $request->get('mothers_last_name'),
'mothers_age' => $request->get('mothers_age'),
'fathers_first_name' => $request->get('fathers_first_name'),
'fathers_last_name' => $request->get('fathers_last_name'),
'fathers_age' => $request->get('fathers_age')
]);
$student->save();
return redirect()->route('student.index')->with('success', 'New teacher data successfully added');
}
/**
* Display the specified resource.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function show($id)
{
//
}
/**
* Show the form for editing the specified resource.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function edit($id)
{
$student = Student::find($id);
return view('student.edit', compact('student', 'id'));
}
/**
* Update the specified resource in storage.
*
* #param \Illuminate\Http\Request $request
* #param int $id
* #return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
$this->validate($request, [
'first_name' => 'required',
'last_name' => 'required',
'Age' => 'required',
'Address' => 'required',
'Grade_Level' => 'required'
]);
$student = Student::find($id);
$student->first_name = $request->get('first_name');
$student->last_name = $request->get('last_name');
$student->Age = $request->get('Age');
$student->Address = $request->get('Address');
$student->Grade_Level = $request->get('Grade_Level');
$student->save();
return redirect()->route('student.index')->with('success', 'Student data successfully updated');
}
/**
* Remove the specified resource from storage.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function destroy($id)
{
$student = Student::find($id);
$student->delete();
return redirect()->route('student.index')->with('success', 'Data successfully deleted');
}
This is my Controller
<div class="container student-create">
<div class="students-info">
<h3>Student's Personal Info</h3>
<form method="post" action="{{url('student')}}">
{{csrf_field()}}
<div class="form-group">
<div class="col-sm">
<label for="Inputfirstname">First Name</label>
<input type="text" class="form-control" name="first_name" placeholder="Enter First Name">
</div>
<div class="col-sm">
<label for="Inputlastname">Last Name</label>
<input type="text" class="form-control" name="last_name" placeholder="Enter Last Name">
</div>
<div class="col-sm">
<label for="Inputlastname">Age</label>
<input type="number" class="form-control" name="Age" placeholder="Enter Last Name">
</div>
</div>
<div class="form-group">
<div class="col-sm">
<label for="InputAddress">Address</label>
<input type="text" class="form-control" name="Address" placeholder="Enter Address">
</div>
<div class="col-sm">
<label for="InputAddress">Grade Level/College Level</label>
<select class="custom-select" name="Grade_Level">
<option selected="">Select Grade Level</option>
<option>Day Care 1</option>
<option>Day Care 2</option>
<option>Kinder Garten 1</option>
<option>Kinder Garten 2</option>
<option>Elementary 1</option>
<option>Elementary 2</option>
<option>Elementary 3</option>
<option>Elementary 4</option>
<option>Elementary 5</option>
<option>Elementary 6</option>
<option>Junior Highschool 1</option>
<option>Junior Highschool 2</option>
<option>Junior Highschool 3</option>
<option>Junior Highschool 4</option>
<option>Senior Highschool 1</option>
<option>Senior Highschool 2</option>
<option>College Level Information Technology 1</option>
<option>College Level Information Technology 2</option>
<option>College Level Information Technology 3</option>
<option>College Level Information Technology 4</option>
</select>
</div>
</div>
<h3>Student's Parents Info</h3>
<div class="form-group">
<div class="col-sm">
<label for="Inputfirstname">Mothers First Name</label>
<input type="text" class="form-control" name="mothers_first_name" placeholder="Enter First Name">
</div>
<div class="col-sm">
<label for="Inputfirstname">Mothers Last Name</label>
<input type="text" class="form-control" name="mothers_last_name" placeholder="Enter Last Name">
</div>
<div class="col-sm">
<label for="Inputfirstname">Mothers Age</label>
<input type="number" class="form-control" name="mothers_age" placeholder="Enter Age">
</div>
</div>
<div class="form-group">
<div class="col-sm">
<label for="Inputfirstname">Fathers First Name</label>
<input type="text" class="form-control" name="fathers_first_name" placeholder="Enter First Name">
</div>
<div class="col-sm">
<label for="Inputfirstname">Fathers Last Name</label>
<input type="text" class="form-control" name="fathers_last_name" placeholder="Enter Last Name">
</div>
<div class="col-sm">
<label for="Inputfirstname">Fathers Age</label>
<input type="number" class="form-control" name="fathers_age" placeholder="Enter Age">
</div>
</div>
<div class="form-group submit">
<button type="button submit" class="btn btn-success">
<i class="fas fa-check"></i> Submit Data
</button>
</div>
</form>
</div>
This is my html code
so the function is like , if i create a data then after that it should redirected to an index or a view page but in my case after submitting/creating data it gives me this error i dont know why
View Page
i have the same page with the same function as this one but it turns out to be okay thats why im wondering why and also this create page that i posted here i started to get this error after i change the style of it and i added some fillable area's like the mother's age, name and etc
I think you can try this.
Change the APP_DEBUG=false to APP_DEBUG=true in .env file and run the following command
php artisan config:clear
It will show the proper error on page
If not work proper, let me know

Resources