In my project I have many things related to user I want all time when I will save a thing of them I save with them userid example:This user have a saved creditscards to associated this data to this user I add in credits cards userid column , So I try to add userid I get a error
this my controller:
<?php
namespace App\Http\Controllers;
use App\CreditCards;
use Illuminate\Http\Request;
use App\ads;
use Validator, Hash;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Tymon\JWTAuth\Exceptions\JWTException;
use Tymon\JWTAuth\Exceptions\TokenInvalidException;
use Config;
use Artisan;
use Tymon\JWTAuth\Facades\JWTAuth;
use Illuminate\Support\Facades\Password;
use Carbon\Carbon;
class CreditsCardsController 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 = CreditCards::where('user_id','=', $request->user_id)->first();
return response()->json(['Cards'=>$Cards]);
}
public function stockcards (Request $request){
$input = $request->all();
$validator = Validator::make($input, [
'number_card'=> 'required',
'expired_date'=> 'required',
'ccv'=> 'required'
] );
if ($validator -> fails()) {
# code...
return response()->json($validator->errors());
}
$Cards = CreditCards::create($input);
//return $this->sendResponse($ads->toArray(), 'Ads created succesfully');
return response()->json(['Cards'=>$Cards]);
}
}
this is my modal and i get a error here :
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Tymon\JWTAuth\Facades\JWTAuth;
use Illuminate\Support\Facades\Auth;
class CreditCards extends Model
{
protected $fillable = [
'number_card', 'expired_date', 'ccv','user_id = '. Auth::user()->id .',
];
}
this my migration table:
Schema::create('ads', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('url');
$table->string('path');
$table->timestamps();
});
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire