logo
down
shadow

Laravel filters won't work when trying to add them


Laravel filters won't work when trying to add them

By : Gerrie Holtzhausen
Date : October 20 2020, 08:10 PM
it fixes the issue To pick up on Aaron Sarays answer, you are most likely filtering the wrong way. Normally additional filters are additional conditions each record has to meet in order to be part of the result. If you consider an Excel table and you filter one column, you won't even have all options to filter for in the second column because you already limited the result and you can only limit it further.
Combine this knowledge with an improved way of filtering and you receive a query like this:
code :
public function filter(Request $request)
{
    $query = $request->input('q');

    $results = \App\Player::query()
        ->when($request->input('status'), function ($query, $status) {
            $query->where('status', $status);
        })
        ->when($request->input('club'), function ($query, $club) {
            $query->where('club', $club);
        })
        ->when($request->input('category'), function ($query, $category) {
            $query->where('category', $category);
        })
        ->when($request->input('remove'), function ($query, $remove) {
            $query->where('remove', $remove);
        })
        ->when($request->input('size'), function ($query, $size) {
            $query->where('size', $size);
        })
        ->when($query, function ($query, $q) {
            $query->where(function ($query) use ($q) {
                $query->where('first_name', 'LIKE', "%$q%")
                    ->orWhere('last_name', 'LIKE', "%$q%")
                    ->orWhere('mobile', 'LIKE', "%$q%")
                    ->orWhere('street_name_number', 'LIKE', "%$q%")
                    ->orWhere('city', 'LIKE', "%$q%");
            });
        })
        ->get();

    if ($results->isNotEmpty()) {
        return view('lists/ekick')->withDetails($results, $query);
    } else {
        return view ('lists/ekick')->with('No Details found. Try to search again !');
    }
}
// option 1: conditional query (preferred!)
$results = Player::query()
    ->when($request->input('q'), function ($query, $q) {
        $query->where('name', 'LIKE', "%$q%");
    })
    ->get();

// option 2: plain php query building... (not very clean code)
$query = Player::query();

if ($request->input('q')) {
    $query->where('name', 'LIKE', '%'.$request->input('q').'%');
}

$results = $query->get();


Share : facebook icon twitter icon
Form submission wont work in Laravel

Form submission wont work in Laravel


By : ShnackShack
Date : March 29 2020, 07:55 AM
Any of those help See https://github.com/laravel/framework/issues/1804.
What I have seen is that Laravel removes all trailing '/' from the URL by redirecting to the url without '/' with code 301. Your browser will be follow this redirection with a GET request instead of a new POST request.
PowerPivot Calculate filters wont work

PowerPivot Calculate filters wont work


By : Huby Franck
Date : March 29 2020, 07:55 AM
it helps some times Urganot,
The desired output is quite simple if you take advantage of all features available in PowerPivot - mainly the ability to create relationships between datatables.
code :
=SUM(Orders[Cost])
=SUM(Goals[Goal])
Laravel Controller Filters: Before filter on a particular method does not work

Laravel Controller Filters: Before filter on a particular method does not work


By : Brixto
Date : March 29 2020, 07:55 AM
Hope this helps The on filter runs if the request has a specific HTTP verb (aka request method). So options are post, get, put etc.
For assigning a filter for an action, except and only are all you need.
laravel wont work with $ ? in the url

laravel wont work with $ ? in the url


By : peter
Date : March 29 2020, 07:55 AM
this will help i have offers api from a website and this return this url , You don't need this route:
code :
Route::get('/offers/data/{data}', "HomeController@offersdone");
Route::get('/offers/data', "HomeController@offersdone");
namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Input;

use App\Http\Requests;
use App\Http\Controllers\Controller;

class HomeController extends Controller
{
    public function offersdone() {
        if (!Input::has("id")) {
            return response("Invalid id");
        }
        $data = Input::all();
        dd($data);
    }
}
array:7 [▼
  "id" => "100"
  "oid" => "12"
  "o_name" => "YurMobile-FI"
  "amount" => "10cy_name=Qoins"
  "user_id" => "1"
  "sig" => "606a5e547ed5c607b10f97a5958f4c38"
  "payout" => "5.250"
]
laravel 4 restful controller wont work

laravel 4 restful controller wont work


By : Tom Kwang
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , I am trying to make the laravel 4 controller in mac terminal by , You need to change Index to getIndex when using RESTful controllers.
Related Posts Related Posts :
  • Running two PHP versions on the same server (STRETCH)
  • Checking if a file has been selected for upload
  • Model not updating laravel
  • How to add a description of words from text to an array, to an array key by passing words?
  • Nginx rewrite rule not not passing variables if "/" is at the end of the url
  • Modify decimal point and thousands separator without changing the number of decimals
  • Remove PHP errors from CLI and PHPMyAdmin
  • Yii2 rest api - Url manager add parameters
  • 1-query batch update array of users using PDO
  • Keep getting error: implode(): Invalid arguments passed when updating data
  • Laravel 5.4 - Correct Validation rule for a required parameter that can be zero
  • What does this code mean: $objPHPExcel->getActiveSheet()->toArray(null, true,true,true)
  • Data not being added to mysql table but echo's the data?
  • While fetch row in PHP
  • IP long string filter
  • How to view first image in list per user as its highlight Profile
  • Insert multiple rows from array
  • PHP : How to remove a duplicate array item ONCE
  • Print the input box text as simple text instead of html tag
  • How to read a string variable in php as $_GET or $_POST?
  • MySQL query fetch array not working
  • LogicException with message '... must return a relationship instance.'
  • PHP - create new array with only selected keys from an existing array
  • How to allow backgrounding a process to survive a session termination?
  • How to redirect to Home page (Default page) in zend framework 2?
  • I want to call a jquery variable in php syntax
  • Disabling the default /?add-to-cart= animation on buttons in Woocommerce
  • How to use query data for another sql query in yii2
  • Replace string enclosed in specified characters based on data type
  • Symfony FormType: how to get prototype in form type file
  • Handle reply messages properly after some operations in php
  • PHP Changed Domain, how to remove old Session Cookies
  • mysqli_stmt::bind_param(): Number of variables doesn't match number of parameters in prepared statement in php
  • Error: Call to a member function update() on array laravel
  • How to change the format of a float number?
  • run ajax requests by order
  • Wordpress Install 404 Error (Cannot view login in browser)
  • Calcinai xero-php pass config once
  • Fatal error calling to undefined function in PHP file
  • Laravel hasMany and belongsTo parameters
  • How do I call a Controller method in php Laravel?
  • How to replace "@" post tag with regex in PHP?
  • Laravel : when insert record in table. How can i add that Record in the list without querying the db
  • It is possible that I could user email address to get customer id from simPRO API?
  • PHP add and merge sql result
  • laravel ckeditor dark theme
  • Laravel belongsToMany not working
  • laravel 5.4 datatables not working jquery $ referenceError
  • Zend Form 2 multiselect field is empty after validation
  • PHP - Laravel 5 get data to html table from 3 SQL database tables with column DATA as headers
  • Can't use token authorization with Laravel Passport
  • splitting lines of dates and presenting in desired format
  • Laravel 5.2 Heroku Deployment Failed to install system packages
  • Laravel relationships - are there multiple *unnecessary* database calls?
  • htaccess rewrite rule for serving index.php from parent directory
  • PHP/MongoDB - $concat aggregation
  • Remove ajax.googleapis.com from my Wordpress site
  • Image saved always empty with Storage::put in Laravel
  • How to count and sort data in junction table
  • Get common number of values in a single array
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org