Search Query Help me with my Search Query, I get this error Call to undefined method App\User::search()
My Controller
<?php
namespace App\Http\Controllers;
use App\User;
use Illuminate\Http\Request;
class SearchController extends Controller
{
>public function search(Request $request) {
if ($request->has('search')) {
$users = User::search($request->get('search'))->get();
}
else {
$users = User::get();
}
return view('admin.clients', compact('users'));
}
}
My Route
Route::get('admin/clients', [
'uses' => 'UserController@getClients',
'as' => 'admin.clients'
]);
<form action="{{ route('clients.search') }}" method="GET" ><input type="text" name="search" ></form>
The error you have is because you are calling this.
User::search($request->get('search'))->get();
but the static method search doesn't exists in you user model, so you need to create it.
In your User Model:
public static function search($request) {
// Your logic
}
public static function search($request) {
return 'admin.clients';
}
I added this to my User Model and I still get this error
"Call to a member function get() on string"
This error is because on your search method you are returning a string, so you can't use
->get() after the search method.
User::search($request->get('search'))->get();
This will work:
User::search($request->get('search'));
but your $users variable will be a string and you will have an error in your view, what are you trying to do in this search method?
I have a table with users and I want to search certain users
I actually get this error now
Invalid argument supplied for foreach()
You get this error because $users is a string('admin.clients').
In the case you have a "type" column on the user table to get the admin users you can do something like this so you don't need the search method in your users model.
// $request->search = 'admin'
$users = User::where('type', $request->search)->get();
Column not found: 1054 Unknown column 'type' in 'where clause' (SQL: select * from users where type =jon)
i got this error now
You need to create the field "type" if you want the query like mine.
Can you show us what your users table is like? So we can find the best solution.
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('first_name');
$table->string('last_name');
$table->string('phone_number');
$table->string('email');
$table->string('company_work');
$table->string('password');
$table->string('address');
$table->string('state');
$table->string('zip');
$table->integer('active')->default(0);
$table->rememberToken();
$table->timestamps();
});
}
Searchers making value-based questions don't need specifically need to discover more data about the item, they are prepared to purchase or play out an activity identifying with that item, administration or action. best essay writing service - australianessay.com . They simply need to discover the thing themselves.
Please sign in or create an account to participate in this conversation.