Laravel - Status Code: 500 Internal Server Error - laravel

hello i want to update my data in DB using V-form but 500 internal server error show:
this is my function in controller:
public function update(Request $request, $id)
{ $data =$request->all();
//
$client = Client::where('id', $data['client_id'])->first();
DB::table('projets')->where('id',$id)->update(['name'=>$data['name'],'durre'=>$data['durre'],'description'=>$data['description'],'owner'=>$client->name,'budget'=>$data['budget']]);
}
and this is my route:
Route::apiResource('projet' ,'API\ProjetController');
and this is the vue code:
modifier(){
this.form.put('api/projet/'+ this.form.id).then(function(){
$('#AjouterProjet').modal('hide')
seww.fire(
'Modifier!',
'Your User has been Updated.',
'success'
)
fire.$emit('ajoutprojet');
}).catch(function(){
})
},

In your route specify the Controller function to execute like this
Route::apiResource('projet' ,'API\ProjetController#update');

When you get 500 error, Check the last file on storage/logs directory and try to find the last error on this file, errors are in this format:
[date_time] [error_message] [stacktrace]

Related

Laravel Jetstream Route Test With Inertia Returns Error Code 500

Out the test it works, I can visit the page and the controller wroks fine. I wrote the following test:
public function test_logged_user_is_not_redirected()
{
PartnerFactory::new()->create();
$request = $this->actingAs(UserFactory::new()->create())
->get('partners')
->assertRedirect('partners');
dd($request->inertiaProps());
}
I get error code 500. This is the controller:
public function index()
{
return Inertia::render('Partners/Index', [
'filters' => \Illuminate\Support\Facades\Request::all($this->getFilters()),
'contacts' => function() {
return $this->getAllContacts();
}
]);
}
This is the route in web.php
Route::get('partners', [PartnersController::class, 'index'])
->name('partners')
->middleware('auth');
Using refresh database, tried url with a '/' before, I still get 500.
edit: without exception handling i get: Trying to get property 'id' of non-object
Found the solution: The user in jetstream MUST have the personal team!

How I can make route API in Laravel with parameter

my route:
Route::get('page/{key_id_fk}', 'PagesApiController#show');
my function:
public function show($key_id_fk)
{
$sub=DefintionDetails::find($key_id_fk);
// $main=Definition::where([['type','=',1],['available','=',1],['id_definition','=',$sub->id_def]])->get();
return response()->json($sub , 200);
}
on post man route is page?key_id_fk=1 give error 404 not found key in data base but didn't read.
You should be accessing page/1 rather than page?key_id_fk=1 as you are not using parameter queries in your request url.
Your route format is page/$key_id_fk.
In the route file:
Route::get('page/{key_id_fk}', 'PagesApiController#show');
In the controller:
public function show($key_id_fk){
$sub = DefintionDetails::find($key_id_fk);
if($sub){
return response()->json(['success' => true, 'sub' => $sub]);
} else {
return response()->json(['success' => false, 'error_message' => 'No data found!']);
}
}
Your postman route:
http://example.com/page/1
You are setting key_id_fk as http://example.com/page/1 in route and passing parameter as http://example.com/page?key_id_fk=1 difference is first one is URL route data and second is GET parameter data to get data from URL route you have this public function show($key_id_fk) and to get data from GET parameter public function show(Request $request) and $request->key_id_fk.
so change URL to this http://example.com/page/1 format
or
change getting method in the controller to public function show(Request $request) and $request->key_id_fk

laravel same function for send two mail to two user with different view page

In laravel cron i have a function like given below :
public function booking_mail()
{
$data_to_mail= DB::table('tbl_booking as book')
->select('book.id as book_id','book.*','twd.id as wk_id','twd.*')
->join('tbl_workers_details as twd', 'twd.id', '=', 'book.worker_id')
->where('book.status','=','0')
->get();
$data['viewpage']='mailtemplates.booking';
$data['toemail']=$agent[0]->email;
$data['listing_no']=$data_to_mail[0]->listing_no;
$data['cv_no']=$data_to_mail[0]->cv_no;
$mail= Mail::send($data['viewpage'], ['userdata'=>$data], function ($message)
use ($data) {
$message->to($data['toemail'],'Booking Mail')->subject('Inquiry Mail For Booking');
if($data['attach']!=''){
$message->attach($data['attach']);
}
});
if($data['attach']!=''){
unlink($data_to_mail[0]->civil_id_copy);
}
$result=DB::table('tbl_booking')
->where('id','=',$data_to_mail[0]->book_id)
->update(array(
'status'=>'1',
));
}
This function is working fine but when i added one for mail function
at the end of the function its not working returning me the error. i
dont know why this happening to me. i want to do this because i want
to send the mail for two different user with two different data and
view code is given below which is returning me the error.
public function booking_mail()
{
$data_to_mail= DB::table('tbl_booking as book')
->select('book.id as book_id','book.*','twd.id as wk_id','twd.*')
->join('tbl_workers_details as twd', 'twd.id', '=', 'book.worker_id')
->where('book.status','=','0')
->get();
$data['user_viewpage']='mailtemplates.enduser_booking';
$data['toemail']=$agent[0]->email;
$data['listing_no']=$data_to_mail[0]->listing_no;
$data['cv_no']=$data_to_mail[0]->cv_no;
//send e-mail to the agent for booking
$mail= Mail::send($data['viewpage'], ['userdata'=>$data], function ($message)
use ($data) {
$message->to($data['toemail'],'Booking Mail')->subject('Inquiry Mail For Booking');
if($data['attach']!=''){
$message->attach($data['attach']);
}
});
$mail= Mail::send($data['user_viewpage'], ['userdata'=>$data], function ($message)
use ($data) {
$message->to($data['toemail'],'Booking Mail')->subject('Confirmation mail');
});
$result=DB::table('tbl_booking')
->where('id','=',$data_to_mail[0]->book_id)
->update(array(
'status'=>'1',
));
}
why this is happening its returning me the error like:
Swift_TransportException in StreamBuffer.php line 268: Connection could not be established with host mail.XXXX.com [Connection timed out #110]
You have undefined $data["user_viewpage"].

laravel ERROR: Trying to get property of non-object on controller laravel

can someone help me with this query why i am getting this error .
hi,
i can't fix the query to set the subject of a mail to be one from db field after $repair->save() in controller
this one works:
Mail::raw($body, function ($message) use ($user, $repair) {
$message->from(Setting::where('setting_key', 'company_email')->first()->setting_value, Setting::where('setting_key', 'company_name')->first()->setting_value);
$message->to('mail#mail.com');
$message->setContentType('text/html');
$message->setSubject(CustomFieldMeta::where('category', 'repairs')->where('parent_id', 108)->where('custom_field_id', 1)->first()->name);
});
or this one:
Mail::raw($body, function ($message) use ($user, $repair) {
$message->from(Setting::where('setting_key', 'company_email')->first()->setting_value, Setting::where('setting_key', 'company_name')->first()->setting_value);
$message->to('mail#mail.com');
$message->setContentType('text/html');
$message->setSubject($repair->id);
});
and this one witch i need is not working:
Mail::raw($body, function ($message) use ($user, $repair) {
$message->from(Setting::where('setting_key', 'company_email')->first()->setting_value, Setting::where('setting_key', 'company_name')->first()->setting_value);
$message->to('mail#mail.com');
$message->setContentType('text/html');
$message->setSubject(CustomFieldMeta::where('category', 'repairs')->where('parent_id', $repair->id)->where('custom_field_id', 1)->first()->name);
});
error: at HandleExceptions->handleError('8', 'Trying to get property of non-object', '/public_html/app/Http/Controllers/RepairController.php', '188', array('message' => object(Message), 'user' => object(User), 'repair' => object(Repair))) in RepairController.php line 188
Thank you.

When i am trying to send mail from contactUS form getting this error using swiftmailer in Laravel 5.2

when i am trying to send Mail through Contact Us Form receiving this Error
"Address in mailbox given [] does not comply with RFC 2822, 3.6.2."
I try search to find solution but I cannot find one. I edited config/mail.php
public function sendContactInfo(ContactMeRequest $request)
{
$data = $request->only('name', 'email');
$emailto="******#gmail.com";
$data['messageLines'] = explode("\n", $request->get('message'));
Mail::send('publicPages.contactus', $data, function ($message) use ($emailto) {
$message->subject('Contact Us Form: ')
->to(config('blog.contact_email'))
->replyTo($data['email']);
});
return back()
->withSuccess("Thank you for your message. It has been sent.");
}
with configuration file
i am following this tutorial
Laravel Send Mail
use $data['email']
Mail::send('publicPages.contactus', $data, function ($message) use ($emailto,$data['email']) {
$message->subject('Contact Us Form: ')
->to(config('blog.contact_email'))
->replyTo($data['email']);
});

Resources