After upgrading to laravel 5.6.21 from 5.5.28 i get this error:
Method Illuminate\Http\Request::setTrustedHeaderName does not exist.
further info from log:
laravel.ERROR: Method Illuminate\Http\Request::setTrustedHeaderName
does not exist. {"exception":"[object] (BadMethodCallException(code:
0): Method Illuminate\Http\Request::setTrustedHeaderName does not
exist. at
/home/vagrant/slf/vendor/laravel/framework/src/Illuminate/Support/Traits/Macroable.php:99)
[stacktrace]
#0 /home/vagrant/slf/vendor/fideloper/proxy/src/TrustProxies.php(140): Illuminate\\Http\\Request->__call('setTrustedHeade...', Array)
#1 /home/vagrant/slf/vendor/fideloper/proxy/src/TrustProxies.php(53): Fideloper\\Proxy\\TrustProxies->setTrustedProxyHeaderNames(Object(Illuminate\\Http\\Request))
#2 /home/vagrant/slf/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(151): Fideloper\\Proxy\\TrustProxies->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#3 /home/vagrant/slf/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#4 /home/vagrant/slf/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(31): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#5 /home/vagrant/slf/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(151): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#6 /home/vagrant/slf/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#7 /home/vagrant/slf/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(31): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#8 /home/vagrant/slf/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(151): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#9 /home/vagrant/slf/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#10 /home/vagrant/slf/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php(27): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#11 /home/vagrant/slf/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(151): Illuminate\\Foundation\\Http\\Middleware\\ValidatePostSize->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#12 /home/vagrant/slf/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#13 /home/vagrant/slf/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php(51): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#14 /home/vagrant/slf/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(151): Illuminate\\Foundation\\Http\\Middleware\\CheckForMaintenanceMode->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#15 /home/vagrant/slf/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#16 /home/vagrant/slf/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(104): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#17 /home/vagrant/slf/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(151): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))
#18 /home/vagrant/slf/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(116): Illuminate\\Foundation\\Http\\Kernel->sendRequestThroughRouter(Object(Illuminate\\Http\\Request))
#19 /home/vagrant/slf/public_html/index.php(55): Illuminate\\Foundation\\Http\\Kernel->handle(Object(Illuminate\\Http\\Request))
#20 {main}
any help would be great
What i did to fix it is changing
"fideloper/proxy": "~3.3",
To
"fideloper/proxy": "~4.0",
In the composer.json file, ran $composer update and then in the TrustProxies.php file located at:
App\Http\Middleware\TrustProxies
I changed the protected headers from:
protected $headers = [
Request::HEADER_FORWARDED => 'FORWARDED',
Request::HEADER_X_FORWARDED_FOR => 'X_FORWARDED_FOR',
Request::HEADER_X_FORWARDED_HOST => 'X_FORWARDED_HOST',
Request::HEADER_X_FORWARDED_PORT => 'X_FORWARDED_PORT',
Request::HEADER_X_FORWARDED_PROTO => 'X_FORWARDED_PROTO',
];
To
protected $headers = Request::HEADER_X_FORWARDED_ALL;
Related
Implementing paypal in my laravel 5.8 app
I got error :
Got Http response code 400 when accessing https://api.sandbox.paypal.com/v1/payments/payment/PAYID-NNNNNNNNNN/execute.
My control :
public function paypal_payment_execute()
{
// After Step 1
$apiContext = new \PayPal\Rest\ApiContext(
new \PayPal\Auth\OAuthTokenCredential(
'NNNNN', // ClientID
'NNNNN' // ClientSecret
)
);
$paymentId = request('paymentId');
$PayerID = request('PayerID');
$payment = Payment::get($paymentId, $apiContext);
$execution = new PaymentExecution();
$execution->setPayerId( $PayerID);
$transaction = new Transaction();
$amount = new Amount();
$details = new Details();
$details->setShipping(1.2)
->setTax(1.3)
->setSubtotal(17.50); //
$amount->setCurrency('USD');
$total_sum= 20; // I check this sum is setShipping + setTax + setSubtotal
$amount->setTotal( (integer)$total_sum);
$amount->setDetails($details);
$transaction->setAmount($amount);
$execution->addTransaction( [ $transaction ] ); // !!! I found that here must be an array?
try {
$result = $payment->execute($execution, $apiContext); // Number of error points at this line
} catch (Exception $pce) {
echo '<pre>::'.print_r( json_decode($pce->getData()) );
die("-1 XXZ app/Http/Controllers/PaymentController.php");
}
return $result;
}
I my browse I see output : https://prnt.sc/od3b6v
1) Can somebody say which kind of error is it ?
2) I see lines like :
$this->logger->info
Is it some logging ? Where can I look into it ?
3) That was very strange that error line was shown and not pre output in try catch block:
I expected to see pce->getData output:
} catch (Exception $pce) {
echo '<pre>::'.print_r( json_decode($pce->getData()) );
die("-1 XXZ app/Http/Controllers/PaymentController.php");
}
4) Searching I net I checked that making payment With JS code I set the same total and return urls, like :
<div id="paypal-button"></div>
<script src="https://www.paypalobjects.com/api/checkout.js"></script>
<script>
let total_sum= 20
alert( "-123 total_sum::"+(total_sum) )
paypal.Button.render({
// Configure environment
env: 'sandbox',
client: {
sandbox: 'NNNNN',
production: 'demo_production_client_id'
},
locale: 'en_US',
style: {
size: 'small',
color: 'blue',
shape: 'pill',
},
commit: true,
payment: function(data, actions) {
var payment = actions.payment.create({
"note_to_payer": "Contact us for any questions on your order.",
"intent": "sale",
"payer": {
"payment_method": "paypal"
},
redirect_urls : { //redirect_urls
return_url : '...paypal_payment',
cancel_url : '.../paypal_payment_cancel'
},
transactions: [{
amount: {
total: Number( total_sum ),
currency: 'USD'
}
}]
});
return payment;
},
onAuthorize: function(data, actions) {
return actions.payment.execute().then(function() {
return actions.redirect();
});
}
}, '#paypal-button');
</script>
How fix it ?
composer.json :
"type": "project",
"require": {
"php": "^7.1.3",
...
"laravel/framework": "5.8.*",
"paypal/rest-api-sdk-php": "*",
Modified :
No messages inside of PayPal\Exception\PPConnectionException block anyway.
In your link I noticed that currency code must be checked.
I created my account about 2 weeks ago : https://prnt.sc/od385x
Where can I check currency code (and maybe country ) ?
Is it in setting for any app ? I did not find where currency can be entered.
if any webhooks must be defoned? What are they for ?
I see “Upgrade to a business account” link . Can it be relative to my problem?
**Modified # 2:**
I attach error desctiption on my sercer in laravel.log when I got 400 error :
cat laravel.log :
[2019-07-12 07:30:33] local.ERROR: Got Http response code 400 when accessing https://api.sandbox.paypal.com/v1/payments/payment/PAYID-LUUDOCA2FR59365NU097882X/execute. {"userId":6,"exception":"[object] (PayPal\Exception\PayPalConnectionException(code: 400): Got Http response code 400 when accessing https://api.sandbox.paypal.com/v1/payments/payment/PAYID-LUUDOCA2FR59365NU097882X/execute. at /var/www/html/votes/vendor/paypal/rest-api-sdk-php/lib/PayPal/Core/PayPalHttpConnection.php:207)
[stacktrace]
#0 /var/www/html/votes/vendor/paypal/rest-api-sdk-php/lib/PayPal/Transport/PayPalRestCall.php(78): PayPal\Core\PayPalHttpConnection->execute('{\"payer_id\":\"Z9...')
#1 /var/www/html/votes/vendor/paypal/rest-api-sdk-php/lib/PayPal/Common/PayPalResourceModel.php(104): PayPal\Transport\PayPalRestCall->execute(Array, '/v1/payments/pa...', 'POST', '{\"payer_id\":\"Z9...', Array)
#2 /var/www/html/votes/vendor/paypal/rest-api-sdk-php/lib/PayPal/Api/Payment.php(650): PayPal\Common\PayPalResourceModel::executeCall('/v1/payments/pa...', 'POST', '{\"payer_id\":\"Z9...', NULL, Object(PayPal\Rest\ApiContext), Object(PayPal\Transport\PayPalRestCall))
#3 /var/www/html/votes/app/Http/Controllers/PaymentController.php(108): PayPal\Api\Payment->execute(Object(PayPal\Api\PaymentExecution), Object(PayPal\Rest\ApiContext))
#4 [internal function]: App\Http\Controllers\PaymentController->paypal_payment_execute()
#5 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Routing/Controller.php(54): call_user_func_array(Array, Array)
#6 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(45): Illuminate\Routing\Controller->callAction('paypal_payment_...', Array)
#7 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Routing/Route.php(219): Illuminate\Routing\ControllerDispatcher->dispatch(Object(Illuminate\Routing\Route), Object(App\Http\Controllers\PaymentController), 'paypal_payment_...')
#8 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Routing/Route.php(176): Illuminate\Routing\Route->runController()
#9 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Routing/Router.php(680): Illuminate\Routing\Route->run()
#10 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(30): Illuminate\Routing\Router->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#11 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php(41): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#12 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(163): Illuminate\Routing\Middleware\SubstituteBindings->handle(Object(Illuminate\Http\Request), Object(Closure))
#13 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#14 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php(75): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#15 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(163): Illuminate\Foundation\Http\Middleware\VerifyCsrfToken->handle(Object(Illuminate\Http\Request), Object(Closure))
#16 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#17 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php(49): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#18 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(163): Illuminate\View\Middleware\ShareErrorsFromSession->handle(Object(Illuminate\Http\Request), Object(Closure))
#19 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#20 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(56): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#21 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(163): Illuminate\Session\Middleware\StartSession->handle(Object(Illuminate\Http\Request), Object(Closure))
#22 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#23 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php(37): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#24 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(163): Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse->handle(Object(Illuminate\Http\Request), Object(Closure))
#25 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#26 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php(66): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#27 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(163): Illuminate\Cookie\Middleware\EncryptCookies->handle(Object(Illuminate\Http\Request), Object(Closure))
#28 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#29 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(104): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#30 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Routing/Router.php(682): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#31 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Routing/Router.php(657): Illuminate\Routing\Router->runRouteWithinStack(Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request))
#32 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Routing/Router.php(623): Illuminate\Routing\Router->runRoute(Object(Illuminate\Http\Request), Object(Illuminate\Routing\Route))
#33 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Routing/Router.php(612): Illuminate\Routing\Router->dispatchToRoute(Object(Illuminate\Http\Request))
#34 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(176): Illuminate\Routing\Router->dispatch(Object(Illuminate\Http\Request))
#35 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(30): Illuminate\Foundation\Http\Kernel->Illuminate\Foundation\Http\{closure}(Object(Illuminate\Http\Request))
#36 /var/www/html/votes/vendor/proengsoft/laravel-jsvalidation/src/RemoteValidationMiddleware.php(53): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#37 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(163): Proengsoft\JsValidation\RemoteValidationMiddleware->handle(Object(Illuminate\Http\Request), Object(Closure))
#38 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#39 /var/www/html/votes/vendor/barryvdh/laravel-debugbar/src/Middleware/InjectDebugbar.php(65): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#40 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(163): Barryvdh\Debugbar\Middleware\InjectDebugbar->handle(Object(Illuminate\Http\Request), Object(Closure))
#41 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#42 /var/www/html/votes/vendor/fideloper/proxy/src/TrustProxies.php(57): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#43 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(163): Fideloper\Proxy\TrustProxies->handle(Object(Illuminate\Http\Request), Object(Closure))
#44 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#45 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#46 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(163): Illuminate\Foundation\Http\Middleware\TransformsRequest->handle(Object(Illuminate\Http\Request), Object(Closure))
#47 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#48 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#49 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(163): Illuminate\Foundation\Http\Middleware\TransformsRequest->handle(Object(Illuminate\Http\Request), Object(Closure))
#50 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#51 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php(27): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#52 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(163): Illuminate\Foundation\Http\Middleware\ValidatePostSize->handle(Object(Illuminate\Http\Request), Object(Closure))
#53 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#54 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php(62): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#55 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(163): Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode->handle(Object(Illuminate\Http\Request), Object(Closure))
#56 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#57 /var/www/html/votes/vendor/itsgoingd/clockwork/Clockwork/Support/Laravel/ClockworkMiddleware.php(29): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#58 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(163): Clockwork\Support\Laravel\ClockworkMiddleware->handle(Object(Illuminate\Http\Request), Object(Closure))
#59 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#60 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(104): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#61 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(151): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#62 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(116): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter(Object(Illuminate\Http\Request))
#63 /var/www/html/votes/public/index.php(55): Illuminate\Foundation\Http\Kernel->handle(Object(Illuminate\Http\Request))
#64 {main}
"}
Casn something be found in this error text?
It breaks my mind why try { block does not trigger...
I am trying to validate my user input which contains two input fields "title" and "description" after click on floating action button but I am getting an error when I do that.
notes_detail_widget.dart
class NoteDetailsWidgetState extends State<NoteDetailsWidget> {
final _formKey = new GlobalKey<FormState>();
String _title;
String _description;
_submit() {
if (_formKey.currentState.validate()) {
_formKey.currentState.save();
}
}
#override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text("Edit note data"),
),
body: new Form(
child: new Container(
margin: new EdgeInsets.all(16.0),
child: new Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
new Container(
child: new TextFormField(
decoration: new InputDecoration(
labelText: "Title",
border: InputBorder.none,
),
validator: (val) =>
val.isNotEmpty ? null : "Title must not be empty",
onSaved: (val) => _title = val),
),
new Container(
child: new Divider(
color: Colors.black,
)),
new TextFormField(
decoration: new InputDecoration(
labelText: "Description",
border: InputBorder.none,
),
keyboardType: TextInputType.multiline,
maxLines: 3,
validator: (val) =>
val.isNotEmpty ? null : "Description must not be empty",
onSaved: (val) => _description = val,
)
])),
),
floatingActionButton: new FloatingActionButton(
onPressed: () => _submit(), child: new Icon(Icons.check)),
);
}
}
Error Log:
I/flutter ( 8055): ══╡ EXCEPTION CAUGHT BY GESTURE ╞═══════════════════════════════════════════════════════════════════
I/flutter ( 8055): The following NoSuchMethodError was thrown while handling a gesture:
I/flutter ( 8055): The method 'validate' was called on null.
I/flutter ( 8055): Receiver: null
I/flutter ( 8055): Tried calling: validate()
I/flutter ( 8055):
I/flutter ( 8055): When the exception was thrown, this was the stack:
I/flutter ( 8055): #0 Object.noSuchMethod (dart:core/runtime/libobject_patch.dart:50:5)
I/flutter ( 8055): #1 NoteDetailsWidgetState._submit (package:notes_crud_app/note_details_widget.dart:16:31)
I/flutter ( 8055): #2 NoteDetailsWidgetState.build.<anonymous closure> (package:notes_crud_app/note_details_widget.dart:61:28)
I/flutter ( 8055): #3 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:507:14)
I/flutter ( 8055): #4 _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:562:30)
I/flutter ( 8055): #5 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:102:24)
I/flutter ( 8055): #6 TapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:242:9)
I/flutter ( 8055): #7 TapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:175:7)
I/flutter ( 8055): #8 PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:315:9)
I/flutter ( 8055): #9 PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:73:12)
I/flutter ( 8055): #10 PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:101:11)
I/flutter ( 8055): #11 _WidgetsFlutterBinding&BindingBase&GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:180:19)
I/flutter ( 8055): #12 _WidgetsFlutterBinding&BindingBase&GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:158:22)
I/flutter ( 8055): #13 _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:138:7)
I/flutter ( 8055): #14 _WidgetsFlutterBinding&BindingBase&GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:101:7)
I/flutter ( 8055): #15 _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:85:7)
I/flutter ( 8055): #16 _invoke1 (dart:ui/hooks.dart:168:13)
I/flutter ( 8055): #17 _dispatchPointerDataPacket (dart:ui/hooks.dart:122:5)
I am quite new to both Dart and Flutter. Please guide.
you didn't add the form key inside the form
body:new Form(
key: _formKey,
child: new Column(
//rest of the code
)
),
I am trying to delete using ajax in laravel but it shows me error like 500 (Internal Server Error), i know its a token error but i am passing a token too still getting same error. without ajax i am able to delete a record.
Route:
Route::get('users/delete/{id}','UserController#destroy');
HTML
<button type="button" class="btn btn-sm btn-outline-danger js-sweetalert" data-token="{{ csrf_token() }}" data-id="{{$obj->id}}" title="Delete" data-type="confirm"><i class="fa fa-trash-o"></i></button>
<script>
$(function () {
$('.js-sweetalert').on('click', function (e) {
e.preventDefault();
var type = $(this).data('type');
var id = $(this).data('id');
var token = $(this).data("token");
var url = $(this).attr("data-link");
if (type === 'confirm') {
showConfirmMessage(id,token,url);
}
});
});
function showConfirmMessage(id,token,url) {
swal({
title: "Are you sure?",
text: "You will not be able to recover this imaginary file!",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#dc3545",
confirmButtonText: "Yes, delete it!",
closeOnConfirm: false
}, function () {
$.ajax({
type: 'GET',
url: "http://localhost:82/reports.laravel.com/public/users/delete/"+id,
data: {
id: id,
_token: token
},
success: function (data) {
console.log("it Work");
if(data==true){
swal("Deleted!", "Your imaginary file has been deleted.", "success");
}
}
});
});
}
</script>
Controller:
class UserController extends Controller
{
public function destroy($id)
{
$user = User::find($id);
$deleted = $user->delete();
if($deleted){
return true;
}
}
}
Log:
[2018-09-19 09:58:18] local.ERROR: The Response content must be a string or object implementing __toString(), "boolean" given. {"userId":1,"email":"ansari#gmail.com","exception":"[object] (UnexpectedValueException(code: 0): The Response content must be a string or object implementing __toString(), \"boolean\" given. at C:\\xampp\\htdocs\
eports.laravel.com\\vendor\\symfony\\http-foundation\\Response.php:394)
[stacktrace]
#0 C:\\xampp\\htdocs\
eports.laravel.com\\vendor\\laravel\\framework\\src\\Illuminate\\Http\\Response.php(45): Symfony\\Component\\HttpFoundation\\Response->setContent(true)
#1 C:\\xampp\\htdocs\
eports.laravel.com\\vendor\\symfony\\http-foundation\\Response.php(202): Illuminate\\Http\\Response->setContent(true)
#2 C:\\xampp\\htdocs\
eports.laravel.com\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php(747): Symfony\\Component\\HttpFoundation\\Response->__construct(true)
#3 C:\\xampp\\htdocs\
eports.laravel.com\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php(719): Illuminate\\Routing\\Router::toResponse(Object(Illuminate\\Http\\Request), true)
#4 C:\\xampp\\htdocs\
eports.laravel.com\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php(679): Illuminate\\Routing\\Router->prepareResponse(Object(Illuminate\\Http\\Request), true)
#5 C:\\xampp\\htdocs\
eports.laravel.com\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(30): Illuminate\\Routing\\Router->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#6 C:\\xampp\\htdocs\
eports.laravel.com\\app\\Http\\Middleware\\IsAdmin.php(21): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#7 C:\\xampp\\htdocs\
eports.laravel.com\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(151): App\\Http\\Middleware\\IsAdmin->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#8 C:\\xampp\\htdocs\
eports.laravel.com\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#9 C:\\xampp\\htdocs\
eports.laravel.com\\vendor\\laravel\\framework\\src\\Illuminate\\Auth\\Middleware\\Authenticate.php(43): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#10 C:\\xampp\\htdocs\
eports.laravel.com\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(151): Illuminate\\Auth\\Middleware\\Authenticate->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#11 C:\\xampp\\htdocs\
eports.laravel.com\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#12 C:\\xampp\\htdocs\
eports.laravel.com\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Middleware\\SubstituteBindings.php(41): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#13 C:\\xampp\\htdocs\
eports.laravel.com\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(151): Illuminate\\Routing\\Middleware\\SubstituteBindings->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#14 C:\\xampp\\htdocs\
eports.laravel.com\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#15 C:\\xampp\\htdocs\
eports.laravel.com\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\VerifyCsrfToken.php(75): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#16 C:\\xampp\\htdocs\
eports.laravel.com\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(151): Illuminate\\Foundation\\Http\\Middleware\\VerifyCsrfToken->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#17 C:\\xampp\\htdocs\
eports.laravel.com\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#18 C:\\xampp\\htdocs\
eports.laravel.com\\vendor\\laravel\\framework\\src\\Illuminate\\View\\Middleware\\ShareErrorsFromSession.php(49): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#19 C:\\xampp\\htdocs\
eports.laravel.com\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(151): Illuminate\\View\\Middleware\\ShareErrorsFromSession->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#20 C:\\xampp\\htdocs\
eports.laravel.com\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#21 C:\\xampp\\htdocs\
eports.laravel.com\\vendor\\laravel\\framework\\src\\Illuminate\\Session\\Middleware\\StartSession.php(63): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#22 C:\\xampp\\htdocs\
eports.laravel.com\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(151): Illuminate\\Session\\Middleware\\StartSession->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#23 C:\\xampp\\htdocs\
eports.laravel.com\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#24 C:\\xampp\\htdocs\
eports.laravel.com\\vendor\\laravel\\framework\\src\\Illuminate\\Cookie\\Middleware\\AddQueuedCookiesToResponse.php(37): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#25 C:\\xampp\\htdocs\
eports.laravel.com\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(151): Illuminate\\Cookie\\Middleware\\AddQueuedCookiesToResponse->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#26 C:\\xampp\\htdocs\
eports.laravel.com\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#27 C:\\xampp\\htdocs\
eports.laravel.com\\vendor\\laravel\\framework\\src\\Illuminate\\Cookie\\Middleware\\EncryptCookies.php(66): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#28 C:\\xampp\\htdocs\
eports.laravel.com\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(151): Illuminate\\Cookie\\Middleware\\EncryptCookies->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#29 C:\\xampp\\htdocs\
eports.laravel.com\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#30 C:\\xampp\\htdocs\
eports.laravel.com\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(104): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#31 C:\\xampp\\htdocs\
eports.laravel.com\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php(681): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))
#32 C:\\xampp\\htdocs\
eports.laravel.com\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php(656): Illuminate\\Routing\\Router->runRouteWithinStack(Object(Illuminate\\Routing\\Route), Object(Illuminate\\Http\\Request))
#33 C:\\xampp\\htdocs\
eports.laravel.com\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php(622): Illuminate\\Routing\\Router->runRoute(Object(Illuminate\\Http\\Request), Object(Illuminate\\Routing\\Route))
#34 C:\\xampp\\htdocs\
eports.laravel.com\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php(611): Illuminate\\Routing\\Router->dispatchToRoute(Object(Illuminate\\Http\\Request))
#35 C:\\xampp\\htdocs\
eports.laravel.com\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Kernel.php(176): Illuminate\\Routing\\Router->dispatch(Object(Illuminate\\Http\\Request))
#36 C:\\xampp\\htdocs\
eports.laravel.com\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(30): Illuminate\\Foundation\\Http\\Kernel->Illuminate\\Foundation\\Http\\{closure}(Object(Illuminate\\Http\\Request))
#37 C:\\xampp\\htdocs\
eports.laravel.com\\vendor\\fideloper\\proxy\\src\\TrustProxies.php(57): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#38 C:\\xampp\\htdocs\
eports.laravel.com\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(151): Fideloper\\Proxy\\TrustProxies->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#39 C:\\xampp\\htdocs\
eports.laravel.com\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#40 C:\\xampp\\htdocs\
eports.laravel.com\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest.php(31): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#41 C:\\xampp\\htdocs\
eports.laravel.com\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(151): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#42 C:\\xampp\\htdocs\
eports.laravel.com\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#43 C:\\xampp\\htdocs\
eports.laravel.com\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest.php(31): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#44 C:\\xampp\\htdocs\
eports.laravel.com\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(151): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#45 C:\\xampp\\htdocs\
eports.laravel.com\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#46 C:\\xampp\\htdocs\
eports.laravel.com\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\ValidatePostSize.php(27): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#47 C:\\xampp\\htdocs\
eports.laravel.com\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(151): Illuminate\\Foundation\\Http\\Middleware\\ValidatePostSize->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#48 C:\\xampp\\htdocs\
eports.laravel.com\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#49 C:\\xampp\\htdocs\
eports.laravel.com\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\CheckForMaintenanceMode.php(62): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#50 C:\\xampp\\htdocs\
eports.laravel.com\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(151): Illuminate\\Foundation\\Http\\Middleware\\CheckForMaintenanceMode->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#51 C:\\xampp\\htdocs\
eports.laravel.com\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#52 C:\\xampp\\htdocs\
eports.laravel.com\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(104): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#53 C:\\xampp\\htdocs\
eports.laravel.com\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Kernel.php(151): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))
#54 C:\\xampp\\htdocs\
eports.laravel.com\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Kernel.php(116): Illuminate\\Foundation\\Http\\Kernel->sendRequestThroughRouter(Object(Illuminate\\Http\\Request))
#55 C:\\xampp\\htdocs\
eports.laravel.com\\public\\index.php(55): Illuminate\\Foundation\\Http\\Kernel->handle(Object(Illuminate\\Http\\Request))
#56 {main}
"}
Change accordingly :
Route:
Route::delete('users/delete/{id}','UserController#destroy');
Controller:
class UserController extends Controller
{
public function destroy($id)
{
$deleted = User::find($id)->delete();
if($deleted){
return true;
}
}
}
HTML:
$.ajax({
type: 'DELETE',
url: "http://localhost:82/reports.laravel.com/public/users/delete/"+id,
data: {
"_token": "{{ csrf_token() }}",
"id": id
}
success: function (data) {
console.log("it Work");
if(data==true){
swal("Deleted!", "Your imaginary file has been deleted.", "success");
}
}
});
Add your token in data like this if it won't then please show the error
"_token": "{{ csrf_token() }}",
[2018-09-19 09:58:18] local.ERROR: The Response content must be a string or object implementing __toString(), "boolean" given. {"userId":1,"email":"ansari#gmail.com","exception":"[object] (UnexpectedValueException(code: 0): The Response content must be a string or object implementing __toString(), \"boolean\" given. at C:\\xampp\\htdocs\
eports.laravel.com\vendor\symfony\http-foundation\Response.php:394)
[stacktrace]
Regarding the error it's because you are returning a boolean true in your controller, because you are trigger the UserController#destroy controller with an ajax call, I will suggest you to do this
class UserController extends Controller
{
public function destroy(Request $request)
{
$user = User::findOrFail($id);
if($request->ajax()) {
$user->delete();
return response()->json(['deleted' =>> true, 'user' => $user]);
} else {
$user->delete();
return response()->setContent(true);
}
}
}
My Laravel application is throwing the next error:
(1/1) Error
Class name must be a valid object or a string
in HasRelationships.php line 656
I have to said that right now this project is in a shared hosting but that's the only part that does not works at all. This is the HTML file:
#extends('layouts.app')
#section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-10">
<div class="card">
<div class="card-header text-uppercase text-center"><b>Dashboard administrativo</b></div>
<div class="card-body">
<div class="card mb-3">
<div class="card-header">
<button type="button" class="btn btn-sm btn-primary text-uppercase" style="cursor:default;">Filtrar por</button>
<a class="btn btn-sm btn-secondary text-uppercase" role="button" href="/admin/dashboard/?gender=true">Hombre</a>
<a class="btn btn-sm btn-secondary text-uppercase" role="button" href="/admin/dashboard/?gender=false">Mujer</a>
<button type="button" class="btn btn-sm btn-primary text-uppercase" style="cursor:default;">Ordenar de manera</button>
<a class="btn btn-sm btn-secondary text-uppercase" role="button" href="{{ route('admin.dashboard', ['gender' => request('gender'), 'sort' => 'desc']) }}">Ascendente</a>
<a class="btn btn-sm btn-secondary text-uppercase" role="button" href="{{ route('admin.dashboard', ['gender' => request('gender'), 'sort' => 'asc']) }}">Descendente</a>
<a class="btn btn-sm btn-success text-uppercase" role="button" href="{{ route('admin.dashboard') }}">Reiniciar</a>
</div>
</div>
<div class="card">
<div class="card-header text-uppercase text-center">Usuarios registrados en el sistema</div>
<div class="card-body">
<table class="table table-bordered">
<thead>
<tr>
<th class="text-center">#</th>
<th>Nombre</th>
<th>Correo</th>
<th>Opciones</th>
</tr>
</thead>
<tbody>
#foreach ($users as $user)
<tr>
<td class="text-center">{{ $user->id }}</td>
<td>{{ $user->name }}</td>
<td>{{ $user->email }}</td>
<td>
<div class="btn-group fullwidth" role="group">
Ver
Editar
</div>
</td>
</tr>
#endforeach
</tbody>
</table>
{{ $users->links() }}
</div>
</div>
</div>
</div>
</div>
</div>
</div>
#endsection
And this is my controller:
<?php
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Auth;
use App\Role;
use App\Permission;
use App\User;
use App\Share;
class AdminController extends Controller
{
public function dashboard()
{
$users = new User();
$queries = [];
$columns = [
'gender',
];
foreach ($columns as $column) {
if(request()->has($column)) {
$users = $users->where($column, request($column));
$queries[$column] = request($column);
} // if
} // foreach
if(request()->has('sort')) {
$users = $users->orderBy('name', request('sort'));
$queries['sort'] = request('sort');
} // if
$users = $users->paginate(10)->appends($queries);
return view('admin.dashboard', compact('users'));
} // dashboard
}
Why does my code works perfectly while developing in my machine but it does not while hosted? I was looking online for a solution but everything i got was related with Entrust which i am not using at all. Any idea?
Edit: App\User
<?php
namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Spatie\Permission\Traits\HasRoles;
class User extends Authenticatable
{
use Notifiable, HasRoles;
/**
* The attributes that are mass assignable.
*
* #var array
*/
protected $fillable = [
'name', 'email', 'password', 'gender', 'identification', 'phone', 'country', 'city', 'provider', 'provider_id', 'birthday', 'referred_by', 'affiliate_id',
];
/**
* The attributes that should be hidden for arrays.
*
* #var array
*/
protected $hidden = [
'password', 'remember_token',
];
public function shares()
{
return $this->hasMany('App\Share');
}
public function storeProvider()
{
return $this->hasOne('App\Provider');
}
public function messages()
{
return $this->hasMany('App\Message');
}
}
This is the whole error:
(1/1) Error
Class name must be a valid object or a string
in HasRelationships.php line 656
at Model->newRelatedInstance(null)in HasRelationships.php line 479
at Model->morphToMany(null, 'model', null, null, 'role_id')in HasRoles.php line 47
at User->roles()in HasAttributes.php line 411
at Model->getRelationshipFromMethod('roles')in HasAttributes.php line 397
at Model->getRelationValue('roles')in HasAttributes.php line 327
at Model->getAttribute('roles')in Model.php line 1475
at Model->__get('roles')in HasRoles.php line 158
at User->hasRole('administrador')in HasRoles.php line 167
at User->hasRole(array('administrador'))in HasRoles.php line 187
at User->hasAnyRole(array('administrador'))in RoleMiddleware.php line 21
at RoleMiddleware->handle(object(Request), object(Closure), 'administrador')in Pipeline.php line 151
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request))in CheckInformation.php line 36
at CheckInformation->handle(object(Request), object(Closure))in Pipeline.php line 151
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request))in SubstituteBindings.php line 41
at SubstituteBindings->handle(object(Request), object(Closure))in Pipeline.php line 151
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request))in Authenticate.php line 43
at Authenticate->handle(object(Request), object(Closure))in Pipeline.php line 151
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request))in VerifyCsrfToken.php line 68
at VerifyCsrfToken->handle(object(Request), object(Closure))in Pipeline.php line 151
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request))in ShareErrorsFromSession.php line 49
at ShareErrorsFromSession->handle(object(Request), object(Closure))in Pipeline.php line 151
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request))in StartSession.php line 63
at StartSession->handle(object(Request), object(Closure))in Pipeline.php line 151
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request))in AddQueuedCookiesToResponse.php line 37
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure))in Pipeline.php line 151
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request))in EncryptCookies.php line 66
at EncryptCookies->handle(object(Request), object(Closure))in Pipeline.php line 151
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request))in Pipeline.php line 104
at Pipeline->then(object(Closure))in Router.php line 667
at Router->runRouteWithinStack(object(Route), object(Request))in Router.php line 642
at Router->runRoute(object(Request), object(Route))in Router.php line 608
at Router->dispatchToRoute(object(Request))in Router.php line 597
at Router->dispatch(object(Request))in Kernel.php line 176
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))in Pipeline.php line 30
at Pipeline->Illuminate\Routing\{closure}(object(Request))in TrustProxies.php line 57
at TrustProxies->handle(object(Request), object(Closure))in Pipeline.php line 151
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request))in TransformsRequest.php line 31
at TransformsRequest->handle(object(Request), object(Closure))in Pipeline.php line 151
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request))in TransformsRequest.php line 31
at TransformsRequest->handle(object(Request), object(Closure))in Pipeline.php line 151
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request))in ValidatePostSize.php line 27
at ValidatePostSize->handle(object(Request), object(Closure))in Pipeline.php line 151
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request))in CheckForMaintenanceMode.php line 62
at CheckForMaintenanceMode->handle(object(Request), object(Closure))in Pipeline.php line 151
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request))in Pipeline.php line 104
at Pipeline->then(object(Closure))in Kernel.php line 151
at Kernel->sendRequestThroughRouter(object(Request))in Kernel.php line 116
at Kernel->handle(object(Request))in index.php line 55
It seems that you are using Spatie/Laravel-permission, and if your app is working on development server, I guess that php version in your live server is less than 7.0 which is required by this package.
You should check your working php version using phpinfo(); on a file and pointing your browser to that file, this will show which php version is used by your webserver.
eg: you can write down a file info.php with the following content
<?php
phpinfo();
Hope this helps.
As noted by #erubiel and #farid-silva, you may need to address the PHP version on production.
However, the most proximate issue is that Spatie\Permission\Traits\HasRoles::roles calls Illuminate\Database\Eloquent\Concerns\HasRelationships::morphToMany with:
related
table, and
foreignKeyPivot
all set to null.
If you take a look at the code, these values are sourced from the Laravel configuration, namely:
permission.models.role
permission.table_names.model_has_roles, and
permission.column_names.model_morph_key
so it might be worth sanity checking your configuration, namely the permission set of values, to check if these are properly defined on production.
For the update of my post table I want to add a validation to check if an image was uploaded. If no image is uploaded, everything is uploaded except the image, else it means there is an image and that is update.
I tried this in my Controller:
public function update(Request $request, $id)
{
if(request('photo')){
$exploded = explode(',', request('photo'));
$decoded = base64_decode($exploded[1]);
if(str_contains($exploded[0], 'jpeg'))
$extension = 'jpg';
else
$extension = 'png';
$fileName = str_random().'.'.$extension;
$path = public_path().'/'.$fileName;
file_put_contents($path, $decoded);
$post = Post::findOrFail($id);
$post->title = request('title');
$post->description = request('description');
$post->category_id = request('category_id');
$post->user_id = Auth::id();
$post->photo = $fileName;
$post->save();
}
else{
$post = Post::findOrFail($id);
$post->title = request('title');
$post->description = request('description');
$post->category_id = request('category_id');
$post->user_id = Auth::id();
$post->save();
}
return response()->json([
'post' => $post,
], 200);
}
In my vue file I have the following:
editPost(){
if(this.update_post.photo == ''){
axios.put('/api/posts/' + this.update_post.id, {
title: this.update_post.title,
description: this.update_post.description,
category_id: this.update_post.category_id
})
.then(response => {
alert('updated');
this.showPosts();
})
.catch(function(error){
console.log(error);
});
}
else{
axios.put('/api/posts/' + this.update_post.id, {
title: this.update_post.title,
description: this.update_post.description,
category_id: this.update_post.category_id,
photo: this.update_post.photo
})
.then(response => {
alert('updated');
this.showPosts();
})
.catch(function(error){
console.log(error);
});
}
}
When I try to update a post, if no image is inserted I get 500 Internal server error:
app.js:14233 PUT http://myblog.local/api/posts/52 500 (Internal Server Error)
The below are some of the errors I see in the error log:
[2018-06-27 20:55:48] local.ERROR: Undefined offset: 1 {"userId":11,"email":"sidney#lab.com","exception":"[object] (ErrorException(code: 0): Undefined offset: 1 at C:\\xampp\\htdocs\\sidneyblog\\app\\Http\\Controllers\\AdminPostsController.php:66)
[stacktrace]
#0 C:\\xampp\\htdocs\\sidneyblog\\app\\Http\\Controllers\\AdminPostsController.php(66): Illuminate\\Foundation\\Bootstrap\\HandleExceptions->handleError(8, 'Undefined offse...', 'C:\\\\xampp\\\\htdocs...', 66, Array)
#1 [internal function]: App\\Http\\Controllers\\AdminPostsController->update(Object(Illuminate\\Http\\Request), '53')
#2 C:\\xampp\\htdocs\\sidneyblog\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Controller.php(54): call_user_func_array(Array, Array)
#3 C:\\xampp\\htdocs\\sidneyblog\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\ControllerDispatcher.php(45): Illuminate\\Routing\\Controller->callAction('update', Array)
#4 C:\\xampp\\htdocs\\sidneyblog\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Route.php(212): Illuminate\\Routing\\ControllerDispatcher->dispatch(Object(Illuminate\\Routing\\Route), Object(App\\Http\\Controllers\\AdminPostsController), 'update')
#5 C:\\xampp\\htdocs\\sidneyblog\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Route.php(169): Illuminate\\Routing\\Route->runController()
#6 C:\\xampp\\htdocs\\sidneyblog\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php(665): Illuminate\\Routing\\Route->run()
#7 C:\\xampp\\htdocs\\sidneyblog\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(30): Illuminate\\Routing\\Router->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#8 C:\\xampp\\htdocs\\sidneyblog\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Middleware\\SubstituteBindings.php(41): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#9 C:\\xampp\\htdocs\\sidneyblog\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(151): Illuminate\\Routing\\Middleware\\SubstituteBindings->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#10 C:\\xampp\\htdocs\\sidneyblog\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#11 C:\\xampp\\htdocs\\sidneyblog\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\VerifyCsrfToken.php(67): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#12 C:\\xampp\\htdocs\\sidneyblog\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(151): Illuminate\\Foundation\\Http\\Middleware\\VerifyCsrfToken->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#13 C:\\xampp\\htdocs\\sidneyblog\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#14 C:\\xampp\\htdocs\\sidneyblog\\vendor\\laravel\\framework\\src\\Illuminate\\View\\Middleware\\ShareErrorsFromSession.php(49): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#15 C:\\xampp\\htdocs\\sidneyblog\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(151): Illuminate\\View\\Middleware\\ShareErrorsFromSession->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#16 C:\\xampp\\htdocs\\sidneyblog\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#17 C:\\xampp\\htdocs\\sidneyblog\\vendor\\laravel\\framework\\src\\Illuminate\\Session\\Middleware\\StartSession.php(63): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#18 C:\\xampp\\htdocs\\sidneyblog\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(151): Illuminate\\Session\\Middleware\\StartSession->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#19 C:\\xampp\\htdocs\\sidneyblog\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#20 C:\\xampp\\htdocs\\sidneyblog\\vendor\\laravel\\framework\\src\\Illuminate\\Cookie\\Middleware\\AddQueuedCookiesToResponse.php(37): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#21 C:\\xampp\\htdocs\\sidneyblog\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(151): Illuminate\\Cookie\\Middleware\\AddQueuedCookiesToResponse->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#22 C:\\xampp\\htdocs\\sidneyblog\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#23 C:\\xampp\\htdocs\\sidneyblog\\vendor\\laravel\\framework\\src\\Illuminate\\Cookie\\Middleware\\EncryptCookies.php(59): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#24 C:\\xampp\\htdocs\\sidneyblog\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(151): Illuminate\\Cookie\\Middleware\\EncryptCookies->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#25 C:\\xampp\\htdocs\\sidneyblog\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#26 C:\\xampp\\htdocs\\sidneyblog\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(104): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#27 C:\\xampp\\htdocs\\sidneyblog\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php(667): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))
#28 C:\\xampp\\htdocs\\sidneyblog\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php(642): Illuminate\\Routing\\Router->runRouteWithinStack(Object(Illuminate\\Routing\\Route), Object(Illuminate\\Http\\Request))
#29 C:\\xampp\\htdocs\\sidneyblog\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php(608): Illuminate\\Routing\\Router->runRoute(Object(Illuminate\\Http\\Request), Object(Illuminate\\Routing\\Route))
#30 C:\\xampp\\htdocs\\sidneyblog\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php(597): Illuminate\\Routing\\Router->dispatchToRoute(Object(Illuminate\\Http\\Request))
#31 C:\\xampp\\htdocs\\sidneyblog\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Kernel.php(176): Illuminate\\Routing\\Router->dispatch(Object(Illuminate\\Http\\Request))
#32 C:\\xampp\\htdocs\\sidneyblog\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(30): Illuminate\\Foundation\\Http\\Kernel->Illuminate\\Foundation\\Http\\{closure}(Object(Illuminate\\Http\\Request))
#33 C:\\xampp\\htdocs\\sidneyblog\\vendor\\fideloper\\proxy\\src\\TrustProxies.php(57): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#34 C:\\xampp\\htdocs\\sidneyblog\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(151): Fideloper\\Proxy\\TrustProxies->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#35 C:\\xampp\\htdocs\\sidneyblog\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#36 C:\\xampp\\htdocs\\sidneyblog\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest.php(31): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#37 C:\\xampp\\htdocs\\sidneyblog\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(151): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#38 C:\\xampp\\htdocs\\sidneyblog\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#39 C:\\xampp\\htdocs\\sidneyblog\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest.php(31): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#40 C:\\xampp\\htdocs\\sidneyblog\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(151): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#41 C:\\xampp\\htdocs\\sidneyblog\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#42 C:\\xampp\\htdocs\\sidneyblog\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\ValidatePostSize.php(27): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#43 C:\\xampp\\htdocs\\sidneyblog\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(151): Illuminate\\Foundation\\Http\\Middleware\\ValidatePostSize->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#44 C:\\xampp\\htdocs\\sidneyblog\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#45 C:\\xampp\\htdocs\\sidneyblog\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\CheckForMaintenanceMode.php(51): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#46 C:\\xampp\\htdocs\\sidneyblog\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(151): Illuminate\\Foundation\\Http\\Middleware\\CheckForMaintenanceMode->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#47 C:\\xampp\\htdocs\\sidneyblog\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#48 C:\\xampp\\htdocs\\sidneyblog\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(104): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#49 C:\\xampp\\htdocs\\sidneyblog\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Kernel.php(151): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))
#50 C:\\xampp\\htdocs\\sidneyblog\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Kernel.php(116): Illuminate\\Foundation\\Http\\Kernel->sendRequestThroughRouter(Object(Illuminate\\Http\\Request))
#51 C:\\xampp\\htdocs\\sidneyblog\\public\\index.php(55): Illuminate\\Foundation\\Http\\Kernel->handle(Object(Illuminate\\Http\\Request))
#52 {main}
"}
How can I fix that?
In your controller, the condition if(request('photo')) is always true.
To Retrieving Input from the request use Request $request variable. for example:
for file: $request->file('photo');
for other text: $request->input('description');