Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Kris01's avatar

csv import laravel

I have a csv file like this

name  type 

but on my project the 'type' is a foreing key 'type_id', how can I proprely import the data?

0 likes
2 replies
Lara_Love's avatar

get from table like

$user_id = Auth::id();

and

$type_id =Type::where('id','$request->id');

or

$type_id  = '1' ;

and then edit and update it ;)

automica's avatar

@lovertohelp

$type_id =Type::where('id','$request->id');

won't work, as you have enclosed the second half of your where in single quotes.

instead

$type_id =Type::where('id' ,$request->id)->first();

and whilst we're here,

$type_id = '1' ;

id is an integer, so:

$type_id = 1 ;

Please or to participate in this conversation.