Laravel - Method [orderBy] does not exist on Axois Request

Yosef

I'm trying to get some records from my DB and I'm getting Method [orderBy] does not exist I'm making this request with Axois.

Route

Route::get('/get-order-statuses', 'Backend\Orders\OrderStatuses@index');

Controller Code

public function index()
    {
        $statuses = OrderStatuses::orderBy('created_at', 'desc')
            ->get(['id', 'status', 'status_description']);

        return response()
            ->json([
                'statuses' => $statuses
            ]);
    }

Model Code

protected $table = 'order_statuses';
    protected $fillable = [
        'statues', 'status_description', 'userId',
    ];

Vue template

import { get } from '../../helpers/api'
        export default {
            data() {
                return {
                    isLoading: true,
                    loaded: false,
                    statuses: []
                }
            },
            created() {
                get('get-order-statuses')
                    .then((res) => {
                        console.log(res);
                        this.isLoading = false;
                        this.loaded = true;
                    })
            }
u_mulder

orderBy is a method of QueryBuilder, so before using it, you should get instance of QueryBuilder.

Also get does not take fields as it's argument.

Considering abovementioned your query can be rewritten as:

$statuses = OrderStatuses::select('id', 'status', 'status_description')
    ->orderBy('created_at', 'desc')
    ->get();

Or:

$statuses = DB::table('order_statuses')
    ->select('id', 'status', 'status_description')
    ->orderBy('created_at', 'desc')
    ->get();

Also

$statuses = OrderStatuses::all()
    ->select('id', 'status', 'status_description')
    ->orderBy('created_at', 'desc')
    ->get();

Este artigo é coletado da Internet.

Se houver alguma infração, entre em [email protected] Delete.

editar em
0

deixe-me dizer algumas palavras

0comentários
loginDepois de participar da revisão

Artigos relacionados

Method orderBy does not exist in Laravel Eloquent?

Laravel Method notify does not exist

BadMethodCallException: Method Illuminate\Database\Eloquent\Collection::orderBy does not exist

Laravel controller validation Request does not exist

Laravel - Método [orderBy] não existe na solicitação Axois

Laravel - Collection::delete method does not exist

laravel pagination Method links does not exist

Laravel eloquent issue: Method does not exist

Laravel 5.2 - Method links does not exist

Laravel Method [where] does not exist error

Laravel Eloquent collection method does not exist

Laravel - Como resolver o erro Method paginate does not exist

Laravel - BadMethodCallException: Method Illuminate\Validation\Validator::validatePatternName does not exist

BadMethodCallException: Method year does not exist

Laravel - check request method

Laravel Method Illuminate\Database\Eloquent\Collection::toSql does not exist. error

Laravel 8: Method Illuminate\Database\Eloquent\Collection::update does not exist ERROR

Property '' does not exist on type 'Request<ParamsDictionary>'

Property 'authorization' does not exist on type 'Request'

Method save doesnot exist. Laravel

Paypal error - getTransactionFee method does not exist

Java NoSuchMethodException - method does exist in class

Method Illuminate\Support\Collection::offset does not exist

Method Illuminate\Validation\Validator::validateVideo does not exist

the method txpool_inspect does not exist/is not available

Laravel 8. Seeder class does not exist

Laravel Backpack Permission seeding "role does not exist"

Laravel 5.1: Class html does not exist

Laravel 8.1, --plain option does not exist

TOP lista

quentelabel

Arquivo