How to update single column in laravel - updates

I am new in Laravel and I'm trying to create an application. I have created a form and I use a controller to store this form into my database.The form has a drop-down field named "Status".
The "Status" is like "Categories" so I need to change this without changing anything else. I am trying to write the code but I am doing something wrong. You can see my code below:
Controller:
public function show($id)
{
$servicedevice = DeviceService::findOrFail($id);
return view('device_service.show', compact('servicedevice', $servicedevice));
}
public function devicestatus(Request $request)
{
$devstat = DeviceService::FindOrFail($servicedevice->id);
$devstat->status_id = $request->device_id;
$devstat->save();
return back();
}
View:
{!! Form::open(['action' => 'DeviceServiceController#devicestatus']) !!}
{!! Form::select('status_id', $statuslist, null, [
'class' => 'js-example-basic-single',
'style' => 'width:50%'
]) !!}
{!! Form::hidden('id', $servicedevice->id) !!}
{!! Form::submit('ok', ['class' => 'btn btn-sm btn-flat btn-warning']) !!}
{!! Form::close(); !!}
Route:
Route::get('/devicestatus', 'DeviceServiceController#devicestatus');
When I try to change The "Status", returns the following error
MethodNotAllowedHttpException in RouteCollection.php line 218:
in RouteCollection.php line 218
at RouteCollection->methodNotAllowed(array('GET', 'HEAD')) in RouteCollection.php line 205
at RouteCollection->getRouteForMethods(object(Request), array('GET', 'HEAD')) in RouteCollection.php line 158
at RouteCollection->match(object(Request)) in Router.php line 780
at Router->findRoute(object(Request)) in Router.php line 610
at Router->dispatchToRoute(object(Request)) in Router.php line 596
at Router->dispatch(object(Request)) in Kernel.php line 267
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in CheckForMaintenanceMode.php line 46
at CheckForMaintenanceMode->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 104
at Pipeline->then(object(Closure)) in Kernel.php line 149
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 116
at Kernel->handle(object(Request)) in index.php line 54
Can you help me please?

The error message and stack trace tells you exactly what happened:
MethodNotAllowedHttpException
...
RouteCollection->methodNotAllowed(array('GET', 'HEAD'))
You are submitting a form (which is POST method by default) but you only define the route as Route::get.
You need to change that to Route::any or define a second route Route::post to the same URL but with a different method call.

Related

An argument to be passed on the mktime built-in function in PHP. How to pass an argument in a mktime function

Actually, I was trying to run a PHP script on a local server, but unfortuantely i encountered this error
Fatal error: Uncaught ArgumentCountError: mktime() expects at least 1 argument, 0 given in C:\xampp\htdocs\SimplePharmacy-PHP\home.php:240 Stack trace: #0 C:\xampp\htdocs\SimplePharmacy-PHP\home.php(240): mktime() #1 {main} thrown in C:\xampp\htdocs\SimplePharmacy-PHP\home.php on line 240
Below is the PHP code that I was refereed to from my source code.
<?php
$Today = date('y:m:d',mktime()); // Line 238
$new = date('l, F d, Y', strtotime($Today));// Line 239
echo $new; // Line 240
?>
I am trying to disply the current date date and year

Undefined index: product in ps_sharebuttons.php on line 140

I have thousands errors in error_log file,there are large rows with one error :
PHP Notice: Undefined index: product in
/home/ngya/public_html/modules/ps_sharebuttons/ps_sharebuttons.php on
line 140
and the line 140 looks like :
140 $key = 'ps_sharebuttons|' . $params['product']['id_product'];
full code
139 {
140 $key = 'ps_sharebuttons|' . $params['product']['id_product'];
141 if (!empty($params['product']['id_product_attribute'])) {
142 $key .= '|' . $params['product']['id_product_attribute'];
143 }
After 00:00 at night, my time (now is 2 PM) I have at least 3555 errors of this kind. I get an error per second or every 15 seconds.
Please help me!
Screen https://i.stack.imgur.com/6rUwS.jpg
change $params['product']['id_product'] to $_GET['id_product'].

Through an error using Unisharp laravel file manager

i have update laravel 5.3 to 5.4 than i got this error for using laravel filemanager package Unisharp.
FatalErrorException in ItemsController.php line 0: Method
Illuminate\View\View::__toString() must not throw an exception, caught
ErrorException: Cannot use object of type stdClass as array (View:
ProjectName\resources\views\vendor\laravel-filemanager\item.blade.php)
(View:
ProjectName\resources\views\vendor\laravel-filemanager\item.blade.php)
return [
'html' => (string)view($this->getView())->with([
'files' => $files,
'directories' => $directories,
'items' => array_merge($directories, $files)
]),
'working_dir' => parent::getInternalPath($path)
];
add in the vendor views item.blade.php in the line 0
<?php $file = json_decode(json_encode($file),true) ; ?>

Fatal error: Class 'mPDF' not found in myproject/vendor/kartik-v/yii2-mpdf/Pdf.php on line 281

I have used kartik pdf extension to print my report in pdf format.Things are going well in my local computer but when i put my codes in server error appears like this:
Fatal error: Class 'mPDF' not found in myproject/vendor/kartik-v/yii2-mpdf/Pdf.php on line 281
In server i have uploaded yii2-mpdf folder inside kartik-v folder and also mpdf folder.
My code of controller for pdf print:
use kartik\mpdf\Pdf;
public function actionPearlFinancialReport()
{
$pdf = new Pdf([
//'mode' => Pdf::MODE_CORE,
'mode' => Pdf::MODE_UTF8,
'format' => Pdf::FORMAT_A4,
'orientation' => Pdf::ORIENT_PORTRAIT,
'destination' => Pdf::DEST_BROWSER,
'content' => $this->renderPartial('_financial_report', ['model' => $model,'parameter'=>$parameter]),
'cssFile' => '#vendor/kartik-v/yii2-mpdf/assets/kv-mpdf-bootstrap.min.css',
'cssInline'=> '.kv-heading-1{font-size:15px;text-align:center;}',
'options' => ['title' => 'Pearl Financial Report'],
'methods' => [
'SetHeader'=>['Pearl Financial Report'],
'SetFooter'=>['{PAGENO}'],
]
]);
$response = Yii::$app->response;
$response->format = \yii\web\Response::FORMAT_RAW;
$headers = Yii::$app->response->headers;
$headers->add('Content-Type', 'application/pdf');
}
What to do?
Try this
'cssFile' => '#vendor/kartik-v/yii2-mpdf/src/assets/kv-mpdf-bootstrap.min.css',
Try to register this extension with composer:
For example my work directory is c:\xampp\htdocs\my-project
In a command prompt -> cd c:\xampp\htdocs\my-project
And register with this command:
C:\xampp\htdocs\my-project>php c:\xampp\htdocs\composer.phar require kartik-v/yii2-mpdf "dev-master"
I always register kartik's extensions with this metod, I hope want to be useful for you too.

Returning JSON from Postgresql Timestamp fails in Laravel 5.2

I am developing an application with Laravel 5.2 I need to return some JSON response from Postgresql database, but I am getting the following error (I posted the first lines of error message)
in Carbon.php line 425
at Carbon::createFromFormat('Y-m-d H:i:s', '2016-06-07 10:06:23.701566') in Model.php line 2958
at Model->asDateTime('2016-06-07 10:06:23.701566') in Model.php line 2451
at Model->attributesToArray() in Model.php line 2428
at Model->toArray() in Collection.php line 1023
at Collection->Illuminate\Support\{closure}(object(Category))
at array_map(object(Closure), array(object(Category), object(Category))) in Collection.php line 1024
at Collection->toArray() in JsonResponse.php line 48
at JsonResponse->setData(object(Collection)) in JsonResponse.php line 49
the records in database have 2 fields created_at and updated_at which both are timestamp type
this is what is returned and printed by dd() function for one row
"id" => 1
"name" => "category1"
"description" => "category 1 decription "
"created_at" => "2016-06-07 10:06:23.701566"
"updated_at" => "2016-06-07 10:06:23.701566"
]
and this is my function in Controller `use App\Http\Requests;
use App\Category;
class CategoryController extends Controller
{
public function index()
{
$categories = Category::all();
return response()->json($categories);
}
help me please through this issue how to get it working and also let me know if I have to provide any further information
Seems that Carbon is trying to format your date with:
Carbon::createFromFormat('Y-m-d H:i:s', '2016-06-07 10:06:23.701566')
The correct format should be as below, which includes the microseconds.
Carbon::createFromFormat('Y-m-d H:i:s.u', '2016-06-07 10:06:23.701566')
Try putting this in your Category model file.
protected $dateFormat = 'Y-m-d H:i:s.u';