function login(Request $req)
{
$user= User::where("email",$req->input('email'))->get();
return Crypt::decrypt($user[0]->password);
}
then i put :
function login(Request $req)
{
$user= User::where("email",$req->input('email'))->get();
return Crypt::decrypt($user[0]->password)==$req->input('password');
}
I got the following error:
The Response content must be a string or object implementing __toString(), "boolean" given.
Related
My Controller File
public function enquiryExport($id, Request $request)
{
$id[] = $request->explode(",",$id);
return Excel::download(new EnquiryExport($id), 'enquiry.xlsx');
}
and My Export File
protected $id;
function __construct($id) {
$this->id = $id;
}
public function collection()
{
return Enquiry::whereIn('id',explode(",",$this->id))->get();
/* return Enquiry::all(); */
}
Route is like
Route::get('enquiryExport', 'enquiryController#enquiryExport');
Still I am getting this error
"message": "Too few arguments to function App\\Http\\Controllers\\enquiryController::enquiryExport(), 1 passed and exactly 2 expected",
I am checkbox id through AJAX here.
The problems is your Route method.
Get method: the query string (name/value pairs) is sent in the URL of a GET request
Post method: the data sent to the server with POST is stored in the request body of the HTTP request
If you use Get method: try this (I have just read it, not tried)
Route::get('enquiryExport/{id}', 'enquiryController#enquiryExport')->name('enquiryExport');
Submit
If you use Post method: try this (I am used to use this)
Route::post('enquiryExport', 'enquiryController#enquiryExport');
public function enquiryExport(Request $request)
{
return Excel::download(new EnquiryExport($request->input('id')), 'enquiry.xlsx');
}
You can read more here: https://www.w3schools.com/tags/ref_httpmethods.asp
Try this
In controller:
public function enquiryExport(Request $request, $id)
{
return Excel::download(new EnquiryExport($request->id), ''.date('Y-m-d'). '.xlsx', \Maatwebsite\Excel\Excel::XLSX);
}
In Export File:
protected $id;
function __construct($id) {
$this->id = $id;
}
public function collection()
{
return Enquiry::where('id', $this->id)->get();
}
public function map($enquiry): array
{
return [
// $enquiry->WRITE YOUR RECORDS,
// ...
];
}
public function headings(): array
{
return [
//NAME HEADINGS(TITLE) OF YOUR RECORDS IN SIDE SINGLE QUOTATION,
// ...
];
}
In Route:
Route::get('enquiryExport/{id}', 'enquiryController#enquiryExport');
UnexpectedValueException
The Response content must be a string or object implementing __toString(), "object" given.
public function redirectToProvider()
{
/* echo "redirect checking";*/
return Socialite::driver('facebook');
}
public function handleProvidercallback()
{
/* echo "callback coming";*/
$user = Socialite::driver('facebook')->user();
dd($user);
//return $user->name;
}
You need to call the redirect function on the driver
return Socialite::driver('facebook')->redirect();
From the docs
Hope this helps
show error : Missing argument 1 for App\Http\Controllers\AdminLoginController::name()
public function name($username) {
$user = AdminLogin::find($username);
return response()->json($user);
}
AdminLoginController: Its a adminlogin controller code
class AdminLoginController extends Controller{
public function show(){
$res ="Hello world!";
return response()->json($res);
}
public function log() {
$users = AdminLogin::all();
return response()->json($users);
}
public function name($username) {
$user = AdminLogin::where('username',$username)->first();
return response()->json($user);
}
RouteLoginController: Its a adminlogin controller code :
<?php
$app->get('/', function () use ($app) {
return $app->version();
});
$app->group(['prefix' => 'api/v1'], function ($app)
{
$app->get('adminlogin', 'AdminLoginController#show'); //get single route
$app->get('user', 'AdminLoginController#log'); //get single route
$app->get('username', 'AdminLoginController#name'); //get single route
$app->post('adminlogin', 'AdminLoginController#login'); //get single route
});
Error :
(1/1) ErrorException
Missing argument 1 for App\Http\Controllers\AdminLoginController::name()
Your controller method is taking the username param but the route binding is not passing one. Change your route
$app->get('username', 'AdminLoginController#name');
to
$app->get('user/{username}', 'AdminLoginController#name');
If you don't want to change your route, change your controller function signature to the below (as shown in the other answers), and make sure you are passing the 'username' as request param while invoking the url.
public function name(\Illuminate\Http\Request $request) {
$user = AdminLogin::where('username',$request->username)->first();
return response()->json(['user' => $user]);
}
You are probably calling this function using an ajax request and putting the name in the query string. In this case, the name parameter will not be sent as an attribute of the function but will be part of the request object.
You can solve this like so:
public function name(\Illuminate\Http\Request $request) {
$user = AdminLogin::find($request->username);
return response()->json($user);
}
You should try this :
public function name($username) {
$user = AdminLogin::where('username',$username)->first();
return response()->json(['user' => $user]);
}
OR
public function name(\Illuminate\Http\Request $request) {
$user = AdminLogin::where('username',$request->username)->first();
return response()->json(['user' => $user]);
}
i have resource controller
and inside the resource controller the index function
public function index()
{
//
}
now i want to use variable from out side the function
like this
public $data = "data";
public function index() use ($data)
{
return $data;
}
i gat this error
syntax error, unexpected 'use' (T_USE), expecting ';' or '{'
i tried it as function like this
public function data()
{
$data = "data";
return $data;
}
public function index() use (data)
{
}
i gat the same error
syntax error, unexpected 'use' (T_USE), expecting ';' or '{'
so how can i access variable and function from outside the function ..
You need to use this to access to the variable:
public $data = "data";
public function index()
{
return $this->data;
}
How to redirect store to update method? I tryed the following code:
public function store(ProductRequest $request)
{
return $this->update(new Product, $request);
}
public function update(Product $product, ProductRequest $request)
{
// code
}
However, the first parameter of update need an already in database user and the above code does not work as expected. (it update the entire users in db!)
What is the correct way to achieve that?
public function store(UserRequest $request)
{
return $this->maintain(new User, $request);
}
public function update(User $user, UserRequest $request)
{
return $this->maintain($user, $request);
}
private function maintain($user, $request)
{
//code;
}
The model for the update method could be the problem, your code is okay for this part:
public function store(Request $request)
{
return $this->update(new Product, $request);
}
public function update(Product $product, Request $request)
{
$product->fill($request->all())->save();
// code
}
For example, with route model binding:
Route::resource('products', 'ProductController');
Route::model('products', App\Product::class);
Or with a custom binding:
Route::resource('products', 'ProductController');
Route::bind('products', function($param) {
return Product::where('slug', $param)->first();
});
Make sure you are not using get() in custom binding, it will pass back a collection.