How to update email value in laravel












0















We know that laravel has an update () method that updates records using the http "put" method. But I do not know how to create an edpoint in which I will be able to modify the email.






namespace AppHttpControllers;

use IlluminateHttpRequest;
use AppUser;

class UserController extends Controller
{

public function index()
{
return response()->json([
'name' => 'Abigail',
'state' => 'CA'
]);
}


public function store(Request $request)
{
$user = new User();
$user->name = $request->get("name");
$user->email = $request->get("email");
$user->password = $request->get("password");
$user->save();
return response()->json($user->toArray(), 200);
}



public function show($id)
{
//
}


public function edit($id)
{
//
}


public function update(Request $request, $id)
{
//
}


public function destroy($id)
{
//
}
}


And my route:



<?php

use IlluminateHttpRequest;

Route::middleware('auth:api')->get('/user', function (Request $request) {
return $request->user();
});

Route::post('v1/users/create', 'UserController@store');


RESTful APIs made by me tests in Postman. Help me somebody










share|improve this question

























  • All API I have built has always required my own custom controller/methods to create users. You can use laravel's passport mechanism but It also requires your own custom controller. medium.com/techcompose/…

    – Orlando P.
    Nov 21 '18 at 21:24











  • Why don't you use the $fillable property on your models, so that you can simply hydrate your models all at once from the $request object. E.g. $user->update($request->all());. Then it doesn't matter if you send one property or all properties.

    – fubar
    Nov 21 '18 at 21:40
















0















We know that laravel has an update () method that updates records using the http "put" method. But I do not know how to create an edpoint in which I will be able to modify the email.






namespace AppHttpControllers;

use IlluminateHttpRequest;
use AppUser;

class UserController extends Controller
{

public function index()
{
return response()->json([
'name' => 'Abigail',
'state' => 'CA'
]);
}


public function store(Request $request)
{
$user = new User();
$user->name = $request->get("name");
$user->email = $request->get("email");
$user->password = $request->get("password");
$user->save();
return response()->json($user->toArray(), 200);
}



public function show($id)
{
//
}


public function edit($id)
{
//
}


public function update(Request $request, $id)
{
//
}


public function destroy($id)
{
//
}
}


And my route:



<?php

use IlluminateHttpRequest;

Route::middleware('auth:api')->get('/user', function (Request $request) {
return $request->user();
});

Route::post('v1/users/create', 'UserController@store');


RESTful APIs made by me tests in Postman. Help me somebody










share|improve this question

























  • All API I have built has always required my own custom controller/methods to create users. You can use laravel's passport mechanism but It also requires your own custom controller. medium.com/techcompose/…

    – Orlando P.
    Nov 21 '18 at 21:24











  • Why don't you use the $fillable property on your models, so that you can simply hydrate your models all at once from the $request object. E.g. $user->update($request->all());. Then it doesn't matter if you send one property or all properties.

    – fubar
    Nov 21 '18 at 21:40














0












0








0








We know that laravel has an update () method that updates records using the http "put" method. But I do not know how to create an edpoint in which I will be able to modify the email.






namespace AppHttpControllers;

use IlluminateHttpRequest;
use AppUser;

class UserController extends Controller
{

public function index()
{
return response()->json([
'name' => 'Abigail',
'state' => 'CA'
]);
}


public function store(Request $request)
{
$user = new User();
$user->name = $request->get("name");
$user->email = $request->get("email");
$user->password = $request->get("password");
$user->save();
return response()->json($user->toArray(), 200);
}



public function show($id)
{
//
}


public function edit($id)
{
//
}


public function update(Request $request, $id)
{
//
}


public function destroy($id)
{
//
}
}


And my route:



<?php

use IlluminateHttpRequest;

Route::middleware('auth:api')->get('/user', function (Request $request) {
return $request->user();
});

Route::post('v1/users/create', 'UserController@store');


RESTful APIs made by me tests in Postman. Help me somebody










share|improve this question
















We know that laravel has an update () method that updates records using the http "put" method. But I do not know how to create an edpoint in which I will be able to modify the email.






namespace AppHttpControllers;

use IlluminateHttpRequest;
use AppUser;

class UserController extends Controller
{

public function index()
{
return response()->json([
'name' => 'Abigail',
'state' => 'CA'
]);
}


public function store(Request $request)
{
$user = new User();
$user->name = $request->get("name");
$user->email = $request->get("email");
$user->password = $request->get("password");
$user->save();
return response()->json($user->toArray(), 200);
}



public function show($id)
{
//
}


public function edit($id)
{
//
}


public function update(Request $request, $id)
{
//
}


public function destroy($id)
{
//
}
}


And my route:



<?php

use IlluminateHttpRequest;

Route::middleware('auth:api')->get('/user', function (Request $request) {
return $request->user();
});

Route::post('v1/users/create', 'UserController@store');


RESTful APIs made by me tests in Postman. Help me somebody







php laravel laravel-5






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 '18 at 21:30









Magnus Eriksson

7,27041327




7,27041327










asked Nov 21 '18 at 21:20









DGrabowskiDGrabowski

1




1













  • All API I have built has always required my own custom controller/methods to create users. You can use laravel's passport mechanism but It also requires your own custom controller. medium.com/techcompose/…

    – Orlando P.
    Nov 21 '18 at 21:24











  • Why don't you use the $fillable property on your models, so that you can simply hydrate your models all at once from the $request object. E.g. $user->update($request->all());. Then it doesn't matter if you send one property or all properties.

    – fubar
    Nov 21 '18 at 21:40



















  • All API I have built has always required my own custom controller/methods to create users. You can use laravel's passport mechanism but It also requires your own custom controller. medium.com/techcompose/…

    – Orlando P.
    Nov 21 '18 at 21:24











  • Why don't you use the $fillable property on your models, so that you can simply hydrate your models all at once from the $request object. E.g. $user->update($request->all());. Then it doesn't matter if you send one property or all properties.

    – fubar
    Nov 21 '18 at 21:40

















All API I have built has always required my own custom controller/methods to create users. You can use laravel's passport mechanism but It also requires your own custom controller. medium.com/techcompose/…

– Orlando P.
Nov 21 '18 at 21:24





All API I have built has always required my own custom controller/methods to create users. You can use laravel's passport mechanism but It also requires your own custom controller. medium.com/techcompose/…

– Orlando P.
Nov 21 '18 at 21:24













Why don't you use the $fillable property on your models, so that you can simply hydrate your models all at once from the $request object. E.g. $user->update($request->all());. Then it doesn't matter if you send one property or all properties.

– fubar
Nov 21 '18 at 21:40





Why don't you use the $fillable property on your models, so that you can simply hydrate your models all at once from the $request object. E.g. $user->update($request->all());. Then it doesn't matter if you send one property or all properties.

– fubar
Nov 21 '18 at 21:40












1 Answer
1






active

oldest

votes


















0














Looking at your question, I think you need to create a route to link to update method in your controller same way you created a post for creating user.



Route::put('v1/users/client/{id}', 'UserController@update);


OR you can use laravel predefined code to create all CRUD routes.



Route::resource('v1/users/client', 'UserController').


To view all the routes created, use



php artisan route:list


Have a further study on this.






share|improve this answer
























  • Yes you are right. I know what the route will look like but I do not know what the code should look like in the update method to change the email

    – DGrabowski
    Nov 22 '18 at 19:05











  • You need to retrieve User first from your database. You can use eloquent or simple query to do it. You can find more on writing queries here

    – InvincibleElf
    Nov 22 '18 at 22:16











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53420618%2fhow-to-update-email-value-in-laravel%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Looking at your question, I think you need to create a route to link to update method in your controller same way you created a post for creating user.



Route::put('v1/users/client/{id}', 'UserController@update);


OR you can use laravel predefined code to create all CRUD routes.



Route::resource('v1/users/client', 'UserController').


To view all the routes created, use



php artisan route:list


Have a further study on this.






share|improve this answer
























  • Yes you are right. I know what the route will look like but I do not know what the code should look like in the update method to change the email

    – DGrabowski
    Nov 22 '18 at 19:05











  • You need to retrieve User first from your database. You can use eloquent or simple query to do it. You can find more on writing queries here

    – InvincibleElf
    Nov 22 '18 at 22:16
















0














Looking at your question, I think you need to create a route to link to update method in your controller same way you created a post for creating user.



Route::put('v1/users/client/{id}', 'UserController@update);


OR you can use laravel predefined code to create all CRUD routes.



Route::resource('v1/users/client', 'UserController').


To view all the routes created, use



php artisan route:list


Have a further study on this.






share|improve this answer
























  • Yes you are right. I know what the route will look like but I do not know what the code should look like in the update method to change the email

    – DGrabowski
    Nov 22 '18 at 19:05











  • You need to retrieve User first from your database. You can use eloquent or simple query to do it. You can find more on writing queries here

    – InvincibleElf
    Nov 22 '18 at 22:16














0












0








0







Looking at your question, I think you need to create a route to link to update method in your controller same way you created a post for creating user.



Route::put('v1/users/client/{id}', 'UserController@update);


OR you can use laravel predefined code to create all CRUD routes.



Route::resource('v1/users/client', 'UserController').


To view all the routes created, use



php artisan route:list


Have a further study on this.






share|improve this answer













Looking at your question, I think you need to create a route to link to update method in your controller same way you created a post for creating user.



Route::put('v1/users/client/{id}', 'UserController@update);


OR you can use laravel predefined code to create all CRUD routes.



Route::resource('v1/users/client', 'UserController').


To view all the routes created, use



php artisan route:list


Have a further study on this.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 21 '18 at 23:28









InvincibleElfInvincibleElf

9615




9615













  • Yes you are right. I know what the route will look like but I do not know what the code should look like in the update method to change the email

    – DGrabowski
    Nov 22 '18 at 19:05











  • You need to retrieve User first from your database. You can use eloquent or simple query to do it. You can find more on writing queries here

    – InvincibleElf
    Nov 22 '18 at 22:16



















  • Yes you are right. I know what the route will look like but I do not know what the code should look like in the update method to change the email

    – DGrabowski
    Nov 22 '18 at 19:05











  • You need to retrieve User first from your database. You can use eloquent or simple query to do it. You can find more on writing queries here

    – InvincibleElf
    Nov 22 '18 at 22:16

















Yes you are right. I know what the route will look like but I do not know what the code should look like in the update method to change the email

– DGrabowski
Nov 22 '18 at 19:05





Yes you are right. I know what the route will look like but I do not know what the code should look like in the update method to change the email

– DGrabowski
Nov 22 '18 at 19:05













You need to retrieve User first from your database. You can use eloquent or simple query to do it. You can find more on writing queries here

– InvincibleElf
Nov 22 '18 at 22:16





You need to retrieve User first from your database. You can use eloquent or simple query to do it. You can find more on writing queries here

– InvincibleElf
Nov 22 '18 at 22:16




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53420618%2fhow-to-update-email-value-in-laravel%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

MongoDB - Not Authorized To Execute Command

Npm cannot find a required file even through it is in the searched directory

in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith