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.
Related
I got an error when I tried to access detail.blade.php that said "Missing required parameter for [Route: admin.request.update] [URI: admin/request/{request}] [Missing parameter: request].". I don't know where did I do wrong, because I copied the steps and codes exactly like my other project that did the same thing (editing data).
Here is my detail.blade.php :
<form action="{{ route('admin.request.update', $requestStock) }}" method="POST">
#csrf
{{ method_field('PUT') }}
<div class="form-group row">
<label for="name" class="col-sm-2 col-form-label">Name</label>
<div class="col-sm-10">
<textarea class="form-control" id="name" name="name" rows="3" readonly value="{{ $requestStock->name }}"></textarea>
</div>
</div>
<div class="form-group row">
<label for="status" class="col-sm-2 col-form-label">Complete</label>
<div class="col-sm-10">
<select class=" form-control" name="status" id="status">
<option name="status" value="1" {{ $requestStock->status == '1' ? 'selected' : ''}}> Not Completed </option>
<option name="status" value="0" {{ $requestStock->status == '0' ? 'selected' : ''}}> Complete </option>
</select>
</div>
</div>
<button type="submit" class="btn btn-secondary" style="margin-top: 20px; width: 100%">Update</button>
</form>
And this is my RequestPageController :
public function edit(RequestStock $requestStock)
{
return view('admin.request.detail')->with([
'requestStock' => $requestStock,
]);
}
public function update(Request $request, RequestStock $requestStock)
{
$requestStock->status = $request->status;
$requestStock->save();
return redirect()->route('admin.request.index');
}
Route :
Route::namespace("App\Http\Controllers\Admin")->prefix("admin")->name("admin.")->middleware('can:adminpage')->group(function () {
Route::resource("/request", RequestPageController::class);
});
Thank you.
Try the following changes:
Changed Route:
Route::namespace("App\Http\Controllers\Admin")->prefix("admin")->name("admin.")->middleware('can:adminpage')->group(function () {
Route::resource("/request-stock", RequestPageController::class);
});
Changed RequestPageController:
public function edit(RequestStock $requestStock)
{
return view('admin.request-stock.detail')->with([
'requestStock' => $requestStock,
]);
}
public function update(Request $request, RequestStock $requestStock)
{
$requestStock->status = $request->status;
$requestStock->save();
return redirect()->route('admin.request-stock.index');
}
umm hello.
Im new in laravel and i want to create a program for list of workers.
I'm trying to access this route:
http://127.0.0.1:8000/posts/create
and there's error message.
ErrorException
Trying to get property '{"role":"pegawai","name":"asdasdasdasd1","email":"1asdad#ifocaproject.com","updated_at":"2020-05-11T18:26:31.000000Z","created_at":"2020-05-11T18:26:31.000000Z","id":7}' of non-object
this is my controller.
public function create(Request $request)
{
$user = new \App\User;
$user->role = 'pegawai';
$user->name = $request['nama_pegawai'];
$user->email = $request['email'];
$user->password = bcrypt('rahasia');
$user->remember_token = Str::random(60);
$user->save();
$request ->request->add(['user_id'-> $user->id]);
$pegawai = \App\Pegawai::create($request->all());
return redirect('/pegawai')->with('sukses','Data Berhasil Di-input');
}
and this is my blade.
<div class="modal-body">
<form action="/pegawai/create" method="POST">
{{ csrf_field() }}
<div class="form-group">
<label for="exampleFormControlInput1">Nama Pegawai</label>
<input name="nama_pegawai" type="text" class="form-control"
id="exampleFormControlInput1" placeholder="Joni">
</div>
<div class="form-group">
<label for="exampleFormControlInput1">Email</label>
<input name="email" type="text" class="form-control"
id="exampleFormControlInput1" placeholder="eve#ifocaprojec.com">
</div>
<div class="form-group">
<label for="exampleFormControlSelect1">Jenis Kelamin</label>
<select name="jenis_kelamin" class="form-control" id="exampleFormControlSelect1">
<option value="Laki-Laki">Laki-laki</option>
<option value="Perempuan">Perempuan</option>
<option value="-none-">-none-</option>
</select>
</div>
<div class="form-group">
<label for="exampleFormControlInput1">Umur</label>
<input name="umur" type="text" class="form-control" placeholder="Cth:21">
</div>
<div class="form-group">
<label for="exampleFormControlInput1">Agama</label>
<input name="agama" type="text" class="form-control" placeholder="Cth:Islam">
</div>
<div class="form-group">
<label for="exampleFormControlTextarea1">Alamat</label>
<textarea name="alamat" class="form-control" rows="3"></textarea>
</div>
<div class="form-group">
<label for="exampleFormControlSelect1">Divisi</label>
<select name="divisi" class="form-control">
<option value="Inbound">Inbound</option>
<option value="Outbound">Outbound</option>
</select>
</div>
</div>
table user:
table pegawai:
What Am I missing? Any help would be greatly appreciated, Thanks.
And I'm sorry, I'm not very good at English.
You may have typo in code.
Here it must be => instead of ->:
$request->request->add(['user_id' => $user->id]);
I believe you need to reload data from DB after ->save():
.......
$user->save();
$request ->request->add(['user_id'-> $user->fresh()->id]);
I have used made use of ajax before, but have not encounted this sort of problem,
here is my form
<form action="" method="post" enctype="multipart/form-data" class="m-form m-form--fit m-form--label-align-right" id="basicinfoform">
{{ csrf_field() }}
<input type="hidden" value="{{ $studentinfo->id }}" name="studentformid">
<div class="form-group m-form__group row">
<center><label for="sphoto">
<?php
$photo = "student.png";
if($studentinfo->photo !== ""){
$photo = $studentinfo->id.'.'.$studentinfo->photo;
}
?>
<img style="width:180px;height:180px;cursor:pointer;border:2px solid lightblue" id="schoollogo" src="<?php echo asset('images/passports/'.$photo) ?>" alt="">
</label>
<input onchange="getPhoto.call(this);showsavebuttonforviewstudentedit();" type="file" class="form-control m-input newb" style="display:none" value="" id="sphoto" name="sphoto" aria-describedby="emailHelp" >
<br>
<span class="m-form__help text-accent">
<b>Click the image to change it</b>
</span>
</center>
<input type="hidden" value="" id="studentid" name="studentid">
</div>
<div class="form-group m-form__group row">
<div class="col-md-4">
<label for="exampleInputPassword1">
Admission No:
</label>
<input type="text" disabled="disabled" class="form-control m-input m-input--square" value="{{ $studentinfo->admissionid }}">
</div>
<div class="col-md-4">
<label for="exampleInputEmail1">
Full name
</label>
<input type="text" name="fullname" class="form-control m-input m-input--square newb" value="{{ $studentinfo->fullname }}" onchange="showsavebuttonforviewstudentedit()">
</div>
<div class="col-md-4">
<label for="exampleInputPassword1">
Gender
</label>
<!-- <input type="password" class="form-control m-input m-input--square" id="exampleInputPassword1" placeholder="Password"> -->
<select name="gender" id="gender" class="form-control m-input m-input--square newb" onchange="showsavebuttonforviewstudentedit()">
<option value="1" {{($studentinfo->gender == "1") ? "selected" : ""}}>Male</option>
<option value="2" {{($studentinfo->gender == "2") ? "selected" : ""}}>Female</option>
</select>
</div>
</div>
<div class="form-group m-form__group row">
<div class="col-md-4">
<label for="exampleInputEmail1">
Class
</label>
<!-- <input type="text" class="form-control m-input m-input--square" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter email"> -->
<select name="class" id="theclass" class="form-control m-input m-input--square newb" onchange="showsavebuttonforviewstudentedit();getArms();">
#foreach($allclasses as $list)
<option value="{{$list->id}}" {{ ($studentinfo->class == $list->id) ? "selected" : ""}}>{{ $list->classname }}</option>
#endforeach
</select>
</div>
<div class="col-md-4">
<label for="exampleInputPassword1">
Arm
</label>
<select name="arm" id="thearm" class="form-control m-input m-input--square newb" onchange="showsavebuttonforviewstudentedit()">
#foreach($allarms as $list)
<option value="{{$list->id}}" {{ ($studentinfo->arm_id == $list->id) ? "selected" : ""}}>{{ $list->arm }}</option>
#endforeach
</select>
</div>
<div class="col-md-4">
<label for="exampleInputPassword1">
House:
</label>
<select name="house" id="house" class="form-control m-input m-input--square newb" onchange="showsavebuttonforviewstudentedit()">
#foreach($allhouses as $list)
<option value="{{$list->id}}" {{ ($studentinfo->house == $list->id) ? "selected" : ""}}>{{ $list->house }}</option>
#endforeach
</select>
</div>
</div>
<div class="form-group m-form__group row">
<div class="col-md-4">
<label for="exampleInputEmail1">
Date of Birth
</label>
<input type="text" class="form-control m-input m-input--square newb" name=""dob id="dob10" value="{{ $studentinfo->dob}}" onchange="showsavebuttonforviewstudentedit()">
</div>
<div class="col-md-4">
<label for="exampleInputPassword1">
State
</label>
<select name="state" id="stateid" class="form-control m-input m-input--square newb" onchange="getLGA();showsavebuttonforviewstudentedit()">
#foreach($allstates as $list)
<option value="{{$list->StateID}}" {{ ($studentinfo->s_of_o == $list->StateID) ? "selected" : ""}}>{{ $list->State }}</option>
#endforeach
</select>
</div>
<div class="col-md-4">
<label for="exampleInputPassword1">
Local Govt.
</label>
<select name="lga" id="lgafield" class="form-control m-input m-input--square newb" onchange="showsavebuttonforviewstudentedit()">
#foreach($alllga as $list)
<option value="{{$list->lgaId}}" {{ ($studentinfo->lga == $list->lgaId) ? "selected" : ""}}>{{ $list->lga }}</option>
#endforeach
</select>
</div>
</div>
<div class="form-group m-form__group row">
<div class="col-md-4">
<!-- <input type="text" class="form-control m-input m-input--square" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter email"> -->
<button type="submit" id="basicbtn" onclick="return submitStudentDetailInViewStudentPage();" disabled="disabled" class="btn btn-brand">   Save <i class="fa fa-spinner fa-spin" style="display:none"></i>  </button>
</div>
</div>
</div>
</form>
onclick of the save button, ajax is firedup, this is the ajax
form = document.getElementById('basicinfoform');
formdata = new FormData(form);
console.log(formdata)
$.ajax({
url : "/ajax/post/studentinfo",
data: formdata,
method: 'post',
processData: false,
contentType: false,
success : function (res){
if(res){
console.log(res)
}
}
});
return false;
here is my controller
public function viewStudent(Request $request, $studentid = null)
{
if(!Auth::check()){
return redirect('/');
}
if($request){
echo 'yes';
}
if(!is_null($studentid)){
$data['allstates'] = DB::table('tblstates')->get();
$data['alllga'] = DB::table('tbl_lga')->get();
$data['studentinfo'] = DB::table('tblstudents')
->where('id', $studentid)
->first();
return view('Students.viewstudents', $data);
}
return redirect('/all/students');
}
in this controller, i have set a condition to check if request has been made so to make edit, so I simply echoed 'Yes' for the sake of testing and this question. Meaning my ajax response is simply suppose to be 'Yes' string literal, but below is what I get in the as response
<!DOCTYPE html>
<!-- Required meta tags -->
--begin::Base Styles -->
<!--begin::Page Vendors -->
<link href="http://127.0.0.1:8000/assets/vendors/custom/fullcalendar/fullcalendar.bundle.css" rel="stylesheet" type="text/css" />
<!--end::Page Vendors -->
<link href="http://127.0.0.1:8000/assets/vendors/base/vendors.bundle.css" rel="stylesheet" type="text/css" />
<link href="http://127.0.0.1:8000/assets/demo/default/base/style.bundle.css" rel="stylesheet" type="text/css" />
<!-- <link rel="stylesheet" type="text/css" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css"> -->
<!--end::Base Styles -->
<link rel="shortcut icon" href="http://127.0.0.1:8000/assets/demo/default/media/img/logo/favicon.ico" />
<link rel="stylesheet" type="text/css" href="http://127.0.0.1:8000/DataTables/datatables.min.css"/>
<link rel="stylesheet" type="text/css" href="http://127.0.0.1:8000/css/bootstrap.css"/>
I think it should look something like this
public function viewStudent(Request $request, $studentid = null)
{
if(!Auth::check())
{
return redirect('/');
}
if($request)
{
// echo outputs to the server, but you should really return something
// for the requester, thus we will return "YES" to the response
// and since we are returning, it will return and no further executions will made.
return 'yes';
}
if(!is_null($studentid))
{
$data['allstates'] = DB::table('tblstates')->get();
$data['alllga'] = DB::table('tbl_lga')->get();
$data['studentinfo'] = DB::table('tblstudents')
->where('id', $studentid)
->first();
return view('Students.viewstudents', $data);
}
return redirect('/all/students');
}
what happens in your case is, it echos yes, but it keeps executing the rest of the code, and it returns a view file. So you get the html response.
if you need to see the echoed text simply add exit() after the echo statement and you will get the 'Yes' response
if($request){
echo 'yes';
exit();
}
You could use return json for returning data to ajax request like
return response()->json(['success' => 'yes']);
Do not use echo for return value to ajax response
Do some functionality as your requirement in ajax call. I'm filtering table data using the search input.
$.ajax({
headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},
type :"POST",
url :"{{route('filter')}}",
dataType:"JSON",
data :{keyword:keyword,'_token':'{!!csrf_token()!!}'},
success :function(response)
{
if (response.status=='success')
{
$('#table_body').html(response.data);
}
}
});
And now on my controller after fetching tables data using query i send the data on another blade view that i want to return in responce and my code is something like this:-
public function filter(Request $r)
{
$keyword=$r->keyword;
$orders=DB::table('orders')->where('print_orders.address','like','%' .$keyword. '%')->paginate(50);
$html=view('orders',compact('orders'))->render();
if ($this->check_count($orders)>0)
{
return response::json(['status'=>'success','data'=>$html]);
}
else
{
return response::json(['status'=>'fail','Nothing Found!!']);
}
}
I have the following problem when trying to edit an "album", hopefully they can help me, I'm a little frustrated haha.
The Form
<form name="editalbum" action="{{ action('AlbumController#postEdit', $album->id) }}" method="POST" enctype="multipart/form-data">
{{ csrf_field() }}
<fieldset>
<h2>Editar <strong>{{$album->name}}</strong></h2>
<br></br>
<div class="form-group">
<label for="name">Nombre del proyecto</label>
<input name="name" type="text" class="form-control" value="{{ $album->name }}" required>
</div>
<div class="form-group">
<label for="description">Descripción del proyecto</label>
<textarea name="description" rows="10" cols="50" type="text" class="form-control" value="{{ $album->description }}" required></textarea>
</div>
<div class="form-group">
<label for="location">Locación:</label>
<input name="location" type="text" class="form-control" value="{{ $album->location }}" required>
</div>
<div class="form-group">
<label for="year">Año:</label>
<input name="year" type="text" class="form-control" value="{{ $album->year }}" required>
</div>
<button type="submit" class="btn btn-primary">Editar</button>
</fieldset>
</form>
So far I think everything is going well because I try to post in the ID of the model.
The function:
public function postEdit(Request $request, $id)
{
$album = Album::find($id);
$album = Album::all();
if(count($album) > 0){
$album->name = Input::get('name');
$album->description = Input::get('description');
$album->year = Input::get('year');
$album->location = Input::get('location');
$album->save();
Alert::success('Successfully Updated', 'Congratulations');
return view('admin.dashboard');
} else {
Alert::error('Facilities not found', 'Error');
return view('galeries');
}
I think you made error in routes.php
It should look like this:
Route::post('albums/update/{id}', ['uses' => 'AlbumController#postEdit']);
One solution will be to remove the DI Request object
public function postEdit($id)
{
//rest of code
}
note: the param has to be passed as a array
action="{{ action('AlbumController#postEdit', ['id' => $album->id]) }}"
I got this error yesterday and I thought I fixed it. I am submitting an 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>
<input type="hidden" name="id" class="form-control" value="{{$student->id}}">
<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 error says that it relates to my ClientController on line 82.
protected function updateOneStudent($parameters)
{
$studentId = $parameters['id'];
return $this-
>performPutRequest("https://lumenapi.juandmegon.com/students/{$studentId}",
$parameters);
}
It was the same function that was giving me the problem yesterday. The problem was that I was not calling a function. The performPutRequest function is like this.
protected function performPutRequest($url, $parameters = [])
{
$contents = $this->performAuthorizeRequest('PUT', $url, $parameters);
$decodedContents = json_decode($contents);
return $decodedContents->data;
}
Any help would be appreciated.
Thanks beginner for point me in the right direction. I had the code below.
protected function updateOneStudent($parameters)
{
$studentId = $parameters['id';
return $this->performPutRequest("https://lumenapi.juandmegon.com/students/{$studentId}", $parameters);
}
I missed a bracket from the id. So it should look like this
protected function updateOneStudent($parameters)
{
$studentId = $parameters['id'];
return $this->performPutRequest("https://lumenapi.juandmegon.com/students/{$studentId}", $parameters);
}