How to add slug in Cartalyst-Sentinel by adding first_name and last_name?












0















I am doing a project with laravel. And I am using Cartalyst-Sentinel with it. How can I add slug from first_name+last_name in users table from database



I added slug for "roles" table but I don't know How can I add values in "slug" columns in the "users" table by adding first_name and last_name. ex: first_name= "JOHN", last_name="CENA", slug="JOHN-CENA"



Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('email');
$table->string('password');



$table->string('birthday')->nullable();
$table->string('gender')->nullable();

$table->text('permissions')->nullable();
$table->timestamp('last_login')->nullable();
$table->string('first_name')->nullable();
$table->string('last_name')->nullable();
$table->string('slug');
$table->timestamps();

$table->engine = 'InnoDB';
$table->unique('email');

$table->unique('slug');


});

DB::table('roles')->insert(array(
array('id'=>1, 'slug'=> 'admin', 'name'=> 'Admin', 'permissions'=> NULL),
array('id'=>2, 'slug'=> 'user', 'name'=> 'User', 'permissions'=> NULL)
)
);









share|improve this question



























    0















    I am doing a project with laravel. And I am using Cartalyst-Sentinel with it. How can I add slug from first_name+last_name in users table from database



    I added slug for "roles" table but I don't know How can I add values in "slug" columns in the "users" table by adding first_name and last_name. ex: first_name= "JOHN", last_name="CENA", slug="JOHN-CENA"



    Schema::create('users', function (Blueprint $table) {
    $table->increments('id');
    $table->string('email');
    $table->string('password');



    $table->string('birthday')->nullable();
    $table->string('gender')->nullable();

    $table->text('permissions')->nullable();
    $table->timestamp('last_login')->nullable();
    $table->string('first_name')->nullable();
    $table->string('last_name')->nullable();
    $table->string('slug');
    $table->timestamps();

    $table->engine = 'InnoDB';
    $table->unique('email');

    $table->unique('slug');


    });

    DB::table('roles')->insert(array(
    array('id'=>1, 'slug'=> 'admin', 'name'=> 'Admin', 'permissions'=> NULL),
    array('id'=>2, 'slug'=> 'user', 'name'=> 'User', 'permissions'=> NULL)
    )
    );









    share|improve this question

























      0












      0








      0








      I am doing a project with laravel. And I am using Cartalyst-Sentinel with it. How can I add slug from first_name+last_name in users table from database



      I added slug for "roles" table but I don't know How can I add values in "slug" columns in the "users" table by adding first_name and last_name. ex: first_name= "JOHN", last_name="CENA", slug="JOHN-CENA"



      Schema::create('users', function (Blueprint $table) {
      $table->increments('id');
      $table->string('email');
      $table->string('password');



      $table->string('birthday')->nullable();
      $table->string('gender')->nullable();

      $table->text('permissions')->nullable();
      $table->timestamp('last_login')->nullable();
      $table->string('first_name')->nullable();
      $table->string('last_name')->nullable();
      $table->string('slug');
      $table->timestamps();

      $table->engine = 'InnoDB';
      $table->unique('email');

      $table->unique('slug');


      });

      DB::table('roles')->insert(array(
      array('id'=>1, 'slug'=> 'admin', 'name'=> 'Admin', 'permissions'=> NULL),
      array('id'=>2, 'slug'=> 'user', 'name'=> 'User', 'permissions'=> NULL)
      )
      );









      share|improve this question














      I am doing a project with laravel. And I am using Cartalyst-Sentinel with it. How can I add slug from first_name+last_name in users table from database



      I added slug for "roles" table but I don't know How can I add values in "slug" columns in the "users" table by adding first_name and last_name. ex: first_name= "JOHN", last_name="CENA", slug="JOHN-CENA"



      Schema::create('users', function (Blueprint $table) {
      $table->increments('id');
      $table->string('email');
      $table->string('password');



      $table->string('birthday')->nullable();
      $table->string('gender')->nullable();

      $table->text('permissions')->nullable();
      $table->timestamp('last_login')->nullable();
      $table->string('first_name')->nullable();
      $table->string('last_name')->nullable();
      $table->string('slug');
      $table->timestamps();

      $table->engine = 'InnoDB';
      $table->unique('email');

      $table->unique('slug');


      });

      DB::table('roles')->insert(array(
      array('id'=>1, 'slug'=> 'admin', 'name'=> 'Admin', 'permissions'=> NULL),
      array('id'=>2, 'slug'=> 'user', 'name'=> 'User', 'permissions'=> NULL)
      )
      );






      laravel cartalyst-sentinel






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Dec 31 '18 at 11:07









      TarekTarek

      12




      12
























          1 Answer
          1






          active

          oldest

          votes


















          0














          I'm not sure why you would want to have a slug column in the users table in the first place, but you can set the slug automatically when you insert/update a user, you can use Laravel model events or Laravel observers. The event you're interested in is the saving event, which gets called just before updating/creating the user on the database.



          Alternatively, you can also use Laravel mutators so that when the first_name, or last_name property is set, the slug property is also updated.



          In addition, you can make use of Laravel's helper method str_slug(). Which can convert a string into a slug.



          Below is an example with observers:



          app/Observers/UserObserver.php



          namespace AppObserversUserObserver;

          use CartalystSentinelUsersEloquentUser;

          class UserObserver
          {
          public function saving(EloquentUser $user)
          {
          $user->slug = str_slug($user->first_name . ' ' . $user->last_name);
          }
          }


          app/Providers/AppServiceProvider.php



          namespace AppProviders;

          use CartalystSentinelUsersEloquentUser;
          use AppObserversUserObserver;
          use IlluminateSupportServiceProvider;

          class AppServiceProvider extends ServiceProvider
          {
          public function boot()
          {
          EloquentUser::observe(UserObserver::class);
          }
          }


          Now anywhere you do something like:



          $user = Sentinel::register([
          'first_name' => 'John',
          'last_name' => 'Cena',
          'email' => 'JohnCena@example.com'
          'password' => 'justanexample'
          ]);


          or



          $user->save();


          The user slug would also be saved.






          share|improve this answer























            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%2f53986732%2fhow-to-add-slug-in-cartalyst-sentinel-by-adding-first-name-and-last-name%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














            I'm not sure why you would want to have a slug column in the users table in the first place, but you can set the slug automatically when you insert/update a user, you can use Laravel model events or Laravel observers. The event you're interested in is the saving event, which gets called just before updating/creating the user on the database.



            Alternatively, you can also use Laravel mutators so that when the first_name, or last_name property is set, the slug property is also updated.



            In addition, you can make use of Laravel's helper method str_slug(). Which can convert a string into a slug.



            Below is an example with observers:



            app/Observers/UserObserver.php



            namespace AppObserversUserObserver;

            use CartalystSentinelUsersEloquentUser;

            class UserObserver
            {
            public function saving(EloquentUser $user)
            {
            $user->slug = str_slug($user->first_name . ' ' . $user->last_name);
            }
            }


            app/Providers/AppServiceProvider.php



            namespace AppProviders;

            use CartalystSentinelUsersEloquentUser;
            use AppObserversUserObserver;
            use IlluminateSupportServiceProvider;

            class AppServiceProvider extends ServiceProvider
            {
            public function boot()
            {
            EloquentUser::observe(UserObserver::class);
            }
            }


            Now anywhere you do something like:



            $user = Sentinel::register([
            'first_name' => 'John',
            'last_name' => 'Cena',
            'email' => 'JohnCena@example.com'
            'password' => 'justanexample'
            ]);


            or



            $user->save();


            The user slug would also be saved.






            share|improve this answer




























              0














              I'm not sure why you would want to have a slug column in the users table in the first place, but you can set the slug automatically when you insert/update a user, you can use Laravel model events or Laravel observers. The event you're interested in is the saving event, which gets called just before updating/creating the user on the database.



              Alternatively, you can also use Laravel mutators so that when the first_name, or last_name property is set, the slug property is also updated.



              In addition, you can make use of Laravel's helper method str_slug(). Which can convert a string into a slug.



              Below is an example with observers:



              app/Observers/UserObserver.php



              namespace AppObserversUserObserver;

              use CartalystSentinelUsersEloquentUser;

              class UserObserver
              {
              public function saving(EloquentUser $user)
              {
              $user->slug = str_slug($user->first_name . ' ' . $user->last_name);
              }
              }


              app/Providers/AppServiceProvider.php



              namespace AppProviders;

              use CartalystSentinelUsersEloquentUser;
              use AppObserversUserObserver;
              use IlluminateSupportServiceProvider;

              class AppServiceProvider extends ServiceProvider
              {
              public function boot()
              {
              EloquentUser::observe(UserObserver::class);
              }
              }


              Now anywhere you do something like:



              $user = Sentinel::register([
              'first_name' => 'John',
              'last_name' => 'Cena',
              'email' => 'JohnCena@example.com'
              'password' => 'justanexample'
              ]);


              or



              $user->save();


              The user slug would also be saved.






              share|improve this answer


























                0












                0








                0







                I'm not sure why you would want to have a slug column in the users table in the first place, but you can set the slug automatically when you insert/update a user, you can use Laravel model events or Laravel observers. The event you're interested in is the saving event, which gets called just before updating/creating the user on the database.



                Alternatively, you can also use Laravel mutators so that when the first_name, or last_name property is set, the slug property is also updated.



                In addition, you can make use of Laravel's helper method str_slug(). Which can convert a string into a slug.



                Below is an example with observers:



                app/Observers/UserObserver.php



                namespace AppObserversUserObserver;

                use CartalystSentinelUsersEloquentUser;

                class UserObserver
                {
                public function saving(EloquentUser $user)
                {
                $user->slug = str_slug($user->first_name . ' ' . $user->last_name);
                }
                }


                app/Providers/AppServiceProvider.php



                namespace AppProviders;

                use CartalystSentinelUsersEloquentUser;
                use AppObserversUserObserver;
                use IlluminateSupportServiceProvider;

                class AppServiceProvider extends ServiceProvider
                {
                public function boot()
                {
                EloquentUser::observe(UserObserver::class);
                }
                }


                Now anywhere you do something like:



                $user = Sentinel::register([
                'first_name' => 'John',
                'last_name' => 'Cena',
                'email' => 'JohnCena@example.com'
                'password' => 'justanexample'
                ]);


                or



                $user->save();


                The user slug would also be saved.






                share|improve this answer













                I'm not sure why you would want to have a slug column in the users table in the first place, but you can set the slug automatically when you insert/update a user, you can use Laravel model events or Laravel observers. The event you're interested in is the saving event, which gets called just before updating/creating the user on the database.



                Alternatively, you can also use Laravel mutators so that when the first_name, or last_name property is set, the slug property is also updated.



                In addition, you can make use of Laravel's helper method str_slug(). Which can convert a string into a slug.



                Below is an example with observers:



                app/Observers/UserObserver.php



                namespace AppObserversUserObserver;

                use CartalystSentinelUsersEloquentUser;

                class UserObserver
                {
                public function saving(EloquentUser $user)
                {
                $user->slug = str_slug($user->first_name . ' ' . $user->last_name);
                }
                }


                app/Providers/AppServiceProvider.php



                namespace AppProviders;

                use CartalystSentinelUsersEloquentUser;
                use AppObserversUserObserver;
                use IlluminateSupportServiceProvider;

                class AppServiceProvider extends ServiceProvider
                {
                public function boot()
                {
                EloquentUser::observe(UserObserver::class);
                }
                }


                Now anywhere you do something like:



                $user = Sentinel::register([
                'first_name' => 'John',
                'last_name' => 'Cena',
                'email' => 'JohnCena@example.com'
                'password' => 'justanexample'
                ]);


                or



                $user->save();


                The user slug would also be saved.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jan 19 at 0:44









                MTranMTran

                1,4061119




                1,4061119






























                    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%2f53986732%2fhow-to-add-slug-in-cartalyst-sentinel-by-adding-first-name-and-last-name%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

                    Monofisismo

                    Angular Downloading a file using contenturl with Basic Authentication

                    Olmecas