vendredi 15 février 2019

I want to select my balance "column" From user table laravel

I'm a beginner in laravel framework,I am in the course of developing an API,and I want to select from users table balance of user when I get her Id in api So I do what I found in documentations in my contoller and i use postman to test my work but always I get a error this is my controller:

<?php

namespace App\Http\Controllers;

use App\User;
use Illuminate\Http\Request;

class MyBalanceController extends Controller
{
    public function index(Request $request)
    {
        # code...
        //  $Ads = ads::all();
        //  return $this->sendResponse($Ads->toArray(), 'Ads read succesfully');
        // This is the name of the column you wish to search
        $input = $request->all();
        $validator =    Validator::make($input, [
            'user_id'=> 'required'
        ] );

        $Cards = User::where('user_id','=', $request->user_id)->pluck('balance')->toArray();
        //$user = Auth::user();
       // $Cards = DB::select('select balance from users where id = :id', ['id' => 1]);


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

this is my modal :

<?php

namespace App;

use Illuminate\Notifications\Notifiable;
use Tymon\JWTAuth\Contracts\JWTSubject;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable implements JWTSubject
{
    use Notifiable;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name', 'email', 'password','username','lastname','tel','adress','balance'
    ];
    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];

    /**
     * Get the identifier that will be stored in the subject claim of the JWT.
     *
     * @return mixed
     */
    public function getJWTIdentifier()
    {
        return $this->getKey();
    }
    /**
     * Return a key value array, containing any custom claims to be added to the JWT.
     *
     * @return array
     */
    public function getJWTCustomClaims()
    {
        return [];
    }
}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire