jorgeyoma

Experience

8,750

0 Best Reply Awards

  • Member Since 1 Year Ago
  • 83 Lessons Completed
  • 6 Favorites

18th July, 2018

jorgeyoma left a reply on Validate Unique Slug • 2 months ago

Hi @hdsavani Thanks for your suggestion. My code works ok, but I want to make it more modular.

jorgeyoma started a new conversation Validate Unique Slug • 2 months ago

Hi.

I've been struggling with this and I can't find a solution.

I use slugs for everything that may be included on the url. So I have slugs in posts, tags, categories, products and services.

I do not want to bother my customer with the "slug" term, so I create the slug internally and check it against the title or name on the Controller with a validator.

I know this is a awful code and I have to copy it in all my Controllers. Any idea on how to implement a rule in a more modular and straightforward way?

In this case I have to return the error to the title so it can be shown as I don't have a slug field in the form.

//PostController

    public function store(Request $request){

      $request['slug']=str_slug($request['title'],'_');

      $validator = Validator::make($request->all(),[
        'title'   =>  'required|min:10|max:100',
        'body'    =>  'required|min:50',
        'slug'    =>  'unique:posts,slug'
      ]);

      if($validator->fails()){

        $errors = $validator->errors();

        if($errors->has('slug')){
          return response()->json(
            [ 'message'=>'Error por slug repetido',
              'errors' => ['title' => ['El titulo del Post esta repetido']]
            ], 422);
        }
      }

      $validator->validate();

....

12th July, 2018

jorgeyoma left a reply on Composite Primary Key - Unique Constraint Failed • 2 months ago

Hi.

I'm having a similar problem with Laravel 5.6.

I previously created a tag with 5.5 with no problems. I copy Paste the same code for categories and I'm having a 'too long index name" error.

This worked on nov/17, Laravel 5.5

        Schema::create('taggables', function (Blueprint $table) {
            $table->integer('tag_id')->unsigned();
            $table->integer('taggable_id')->unsigned();
            $table->string('taggable_type');
            $table->primary(['tag_id','taggable_id','taggable_type']);
            $table->timestamps();
        });

This gives me error today, Laravel 5.6

      Schema::create('categoriables', function (Blueprint $table) {
        $table->integer('category_id')->unsigned();
        $table->integer('categoriable_id')->unsigned();
        $table->string('categoriable_type');
        $table->primary(['category_id','categoriable_id','categoriable_type']);
        $table->timestamps();
      });
In Connection.php line 664:
                                                                                                               
  SQLSTATE[42000]: Syntax error or access violation: 1059 Identifier name 'categoriables_category_id_categori  
  able_id_categoriable_type_primary' is too long (SQL: alter table `categoriables` add primary key `categoria  
  bles_category_id_categoriable_id_categoriable_type_primary`(`category_id`, `categoriable_id`, `categoriable  
  _type`))                                                                                                     
                                                                                                               

In Connection.php line 458:
                                                                                                               
  SQLSTATE[42000]: Syntax error or access violation: 1059 Identifier name 'categoriables_category_id_categori  
  able_id_categoriable_type_primary' is too long 

jorgeyoma left a reply on WithCount Not Working With Cache::remember • 2 months ago

@tykus the key was duplicated.

jorgeyoma started a new conversation WithCount Not Working With Cache • 2 months ago

Hi.

I have a function in PostController that searches for the tags that have been used in Posts and gives this data to the view.

I want to cache this info but now it gives me all the tags, no matter if they are used or not.

This works and gives me only the tags with posts.

        $tags =  Tag::withCount(['posts' => function ($query) {
          $query->active();
        }])->having('posts_count','>',0)->get();

This gives me all the tags. What's wrong?

      
$tags = Cache::remember('tags', 3600, function () {

       return  Tag::withCount(['posts' => function ($query) {
          $query->active();
        }])->having('posts_count','>',0)->get();

     });

20th June, 2018

jorgeyoma left a reply on Welcome Email With Create Password Link • 3 months ago

Ok I resolved. This is my function on my User class:

public function sendWelcomeEmail(){

  $token = app('auth.password.broker')->createToken($this);;

  DB::table(config('auth.passwords.users.table'))->insert([
      'email' => $this->email, 
      'token' => $token
  ]);

  $resetUrl= url(config('app.url').route('password.reset', $token, false));

  \Mail::to($this)->send(new Welcome($this, $resetUrl));

}

jorgeyoma left a reply on Welcome Email With Create Password Link • 3 months ago

@Cronix

I'm going to send a welcome email with a link to the reset password page.

I can manage to create the link with:

''' $resetUrl= url(config('app.url').route('password.reset', $token, false));

  \Mail::to($this)->send(new Welcome($this, $resetUrl));

'''

but I can't find how to generate the token and store it on the password_resets table.

any idea?

19th June, 2018

jorgeyoma started a new conversation Welcome Email With Create Password Link • 3 months ago

Hi. I'm creating an app where the admin register the new users and then an email is sent to this new user with a welcome message and a link to create a new password.

This last part I'm having problems as I can't find info on how to generate the token and the link.

This link should redirect the user to a create password page, which is different than the reset password.

Thanks !

8th June, 2018

jorgeyoma left a reply on Return Diferent Data With Resources Depending If User Is Logged In Or Not. • 3 months ago

@tykus, @Snapey , thank you both for your answers, I took out my routes from the api.php and created a group in the web.php to manage my internal calls:

''' Route::group(array('prefix' => 'get'), function () {

Route::get('/posts/{id?}','[email protected]')->name('get.posts');

})

'''

7th June, 2018

jorgeyoma started a new conversation Return Diferent Data With Resources Depending If User Is Logged In Or Not. • 3 months ago

Hi. Im building a simple site with Laravel 5.6 and Vue. I'm using the Resources for giving the info to Vue in json format.

I do not want to implement a complex API as my need is very simple: If the user is logged in the information passed by the Resource will include some extra information than if the user is not logged in.

In this way I want to manage in one PostResource file the information I pass to my admin pages and the public pages.

The problem I have is I can't get the way to check if the user is logged in the right way using the Auth::user().

If I do in the api.php:

Route::get('/posts/{id?}','[email protected]')->name('api.posts');

The Controller always thinks the user is not logged, no matter if the user is logged in or not.

And if I do in the web.php:

Route::group(array('middleware' => 'auth'), function () {

Route::get('api/posts/{id?}','[email protected]')->name('api.posts');

})

The webpage forces me to log in.

How can I implement this in a simple way?

9th April, 2018

jorgeyoma left a reply on Laravel Mix And Node_module Problem With Url In Css • 5 months ago

Hi Bobby.

I read the tutorial and I got a problem in my Apache configuration in the 000-default.conf file.

Thanks for your help.

4th April, 2018

jorgeyoma left a reply on Laravel Mix And Node_module Problem With Url In Css • 5 months ago

Hi Bobby.

I'm using Linux Mint, and I installed everything myself.

My Best.

3rd April, 2018

jorgeyoma left a reply on Laravel Mix And Node_module Problem With Url In Css • 5 months ago

Hi bobby. I'm aware of that but as you can see in my post I dont know how to change that.

Im working in Linux Mint.

2nd April, 2018

jorgeyoma started a new conversation Laravel Mix And Node_module Problem With Url In Css • 5 months ago

Hi. I'm getting a 404 not found in a background image from a css file. I'm working in localhost and the project url is

http://localhost/bulmavue55/public

I'm using npm "blueimp-gallery" so in my project folder I have:

node_modules/blueimp-gallery/css --blueimp-gallery-video.css

This file has the following line:

.blueimp-gallery > .slides > .slide > .video-loading > a { background: url(../img/loading.gif) center no-repeat; background-size: 64px 64px; }

And I get the following error mesage:

GET http://localhost/images/vendor/blueimp-gallery/loading.gif?05992d3434d3589b38a3a5431842d38f 404 (Not Found)

In webpack.mix.js I managed to copy the files to a public folder with

mix.copyDirectory('node_modules/blueimp-gallery/img', 'public/storage/img/site');

so I can find loading.gif at http://localhost/bulmavue55/public/storage/img/site/loading.gif

but I can't get to redirect the url to this direction.

I tried with mix.setPublicPath('public/storage');

but it didnt do any difference.

my js file is located at http://localhost/bulmavue55/public/js/app.js and it has the following line:

/***/ (function(module, exports) {

module.exports = "/images/vendor/blueimp-gallery/loading.gif?05992d3434d3589b38a3a5431842d38f";

/***/ }),

Please your help.

My best,

13th December, 2017

jorgeyoma started a new conversation Probable Security Issue: Restore Page Allows User To Go To Auth Section Without Login • 9 months ago

Hi. This is a behavior I think shouldn't occur. I'm working in localhost with Laravel 5.5.

If I'm in an auth view and I close chrome when I open chrome again it ask me to restore the previuos page. If I said yes I can go over the auth view without having to login again. Just if I go out of this view laravel with ask me to Login again.

I think that If I said yes to restore pages I should be redirected to the login page and then to the last page.

Please check this.

My Best

11th December, 2017

jorgeyoma started a new conversation Delete Gallery If Post Not Created • 9 months ago

Hi. I'm creating a blog page and the user can attach a picture gallery to the post. A Post can have one Gallery and Gallery can be used by other models.

the post is created in mypageurl/admin/post/create

I'm using a JScript outside the Post create form to upload the gallery pictures. In that way I can resize the pictures before sending them to the server.

Now the user submits a Post, with the Post Id a Gallery is created linked to the Post and the Gallery Id is returned. After that the user can create the gallery.

With this way I can upload the Gallery only after the post was created.

....

Post is created => new Gallery is attached to it, new Gallery Id is returned as response.

Upload Gallery #xxxx

I want the user to be able to upload the Gallery when creating the Post. The idea I have is to create a Gallery everytime the user enters mypageurl/admin/post/create and attach the Gallery Id to the Post

Upload Gallery #444

The problem I see is that I can end with several Galleries from not created Post.

Any suggestion?

By Best.

28th April, 2017

jorgeyoma left a reply on Vuejs Transition With Animate.css Does Not Working By Enter Class • 1 year ago

Hi. I'm having the same problems. This is my code:

<template>
  <transition appear mode="in-out" enter-active-class="animated fadeIn" leave-active-class="animated fadeOut">
    <div v-if="isSelected" key="tab-message"><slot></slot></div>
  </transition>

</template>

Both fadeOut and fadeIn are occuring ate the same time, even if I take out the fadeOut animation there is a transposition.

Edit Your Profile
Update

Want to change your profile photo? We pull from gravatar.com.