Abdel Maimouni Abdel Maimouni - 2 years ago 123
PHP Question

Add foreign key to request Laravel

what i am trying to achieve is :
User create a Delivery by a title input,

When the user send the request i want to get the users_id to add it to delivery table as a foreign key.
Here is the deliveries table

public function up()
Schema::create('deliveries', function (Blueprint $table) {

Schema::table('deliveries', function ($table) {


here is the DeliveryController


namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;

use App\User;

class DeliveryController extends Controller
public function index()
return view('delivery.index');

public function create()
return view('delivery.create');

public function store(Request $request)
$this->validate($request, [
'title' => 'required'

$input = $request->all();

$input['users_id'] = Auth::user()->id;


return redirect()->back();


Answer Source

After weeks of researches i found That my Controller Missing This Line :

    use Illuminate\Support\Facades\Input; 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download