Back

Create user from external web application


Daniel posted 3 weeks ago

Hello, everybody,

I'm Daniel, web developer with php experience about 8 years, but I'm new to Laravel. I'm researching how to create a user, from an external web application. Can you help me, what would be the most correct way? I see it is created by the store() function of the app/Http/Controllers/Admin/UserController.php file.

My idea is to create a custom controller, which receives "requests" via url, validates, and creates the user with the data received in the request.

Greetings and thanks,

TorchSK replied 3 weeks ago

First of all I would create the route in routes/api.php file to have the api namespace and other api (optional) authentications available (check official docs)

https://laravel.com/docs/5.8/routing
https://laravel.com/docs/5.8/api-authentication

To validate the data you can simply create form request validation on store() function

https://laravel.com/docs/5.8/validation#form-request-validation

To store the data in the DB you can create fillable attribute on User model with array of fields that can be populated by mass assignment and just do User::create($request->all())

https://laravel.com/docs/5.8/eloquent#mass-assignment

You don't have to create custom controller (but you can if you want of course)

Laravel is just... beautiful! :)

Cameron replied 3 weeks ago

I would add some sort of security to your endpoint or anyone could post to create a new user

Make an api post route , example api/create-user

Point it to a controller method Example Public function create(Request $request){

$user = new User; $user->myfield_1 = “my data where “; $user->save();

}

Post your data from your external app to your new endpoint in laravel

Sarah Taylor replied 2 weeks ago

How can I create external web application for Dissertation Writing Service I need complete guideline in very deep detail?

alicetaylor replied 2 weeks ago

Great info. I love all the posts, I really enjoyed, I would like more information about this, because it is very nice., Thanks for sharing.

zomzom.io

ariana pham replied 2 weeks ago

There are very interesting question and very positive thinking in five nights at candy's your mind so i like this topic so i one suggestion we can use it now bing

Na ta replied 1 week ago

Thanks for the information you shared. douchebag workout 2


Sign in to participate in this thread!



We'd like to thank these amazing companies for supporting us