ramjamx

ramjamx

Member Since 2 Years Ago

Experience Points 2,710
Experience Level 1

2,290 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed 25
Lessons
Completed
Best Reply Awards 0
Best Reply
Awards
  • start-engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist Created with Sketch.

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

13 Mar
2 years ago

ramjamx left a reply on Eloquent Query Finding Similar Results

@zachleigh I tried with (type casting)[http://php.net/manual/en/language.types.type-juggling.php] and as @snapey sugested checking if it is integer with !id==intval($id)

full function now is like this:

  public function getDataByID($id){
    $id = intval($id);
    if(!$id==intval($id)){
      return $error = array('Message'=>'El id sólo puede ser numérico');

      }
      else{
        $curso =  Curso::where('id',$id)->first();
        if(!is_null($curso)){
          $curso_formateado =array(
                              '_id' => (string) $curso->id,
                              'clave' => $curso->clave,
                              'fecha' => $curso->fecha,
                              'titulo' => $curso->titulo,
                              'descripcion' => $curso->descripcion,
                              'video_url' => $curso->video_url,
                              'last_update' => (string) $curso->updated_at->format('U'),
                              'sede' =>  $curso->Sedes,
                            );
          return $curso_formateado;
      }
      else{
        return $error = array('Message'=>'No existe un curso con estos datos');
      }
    }


  }

thankyou guys!

12 Mar
2 years ago

ramjamx left a reply on Eloquent Query Finding Similar Results

@zachleigh my user migration looks like this:

// USERs migration:
    {
      Schema::create('users', function (Blueprint $table) {
         $table->increments('id');
         $table->string('factura')->unique();
         $table->string('email')->unique();
         $table->string('nombre');
         $table->string('apellido');
         $table->string('empresa');
         $table->tinyInteger('nivel');
         $table->timestamps();
     });
    }
// CURSOS migration:
    Schema::create('cursos', function (Blueprint $table) {
             $table->increments('id');
             $table->string('clave')->unique();
             $table->timestamp('fecha');
             $table->string('titulo');
             $table->text('descripcion');
             $table->string('video_url');
             $table->unsignedInteger('sede_id');
             $table->timestamps();
             

         });
         Schema::table('cursos', function($table) {
            $table->foreign('sede_id')->references('id')->on('sedes');
         });
// both are related by the MEMBRESIAS table

{
      Schema::create('membresias', function (Blueprint $table) {
         $table->unsignedInteger('usuario');
         $table->unsignedInteger('curso');
         $table->boolean('asistencia')->default(0);
         $table->boolean('offline')->default(0);
         $table->primary(['usuario', 'curso']);
         $table->timestamps();
     });
     Schema::table('membresias', function($table) {
        $table->foreign('usuario')->references('id')->on('users')->onDelete('cascade');;
        $table->foreign('curso')->references('id')->on('cursos')->onDelete('cascade');;
     });
    }

ramjamx left a reply on Eloquent Query Finding Similar Results

@jlrdw thank you! but I barely found out how to associate a model with a class and foreign id to query on other table "Sedes" for associated items.

I'll try to do it raw but one of the main reasons to use a framework is for get less complicated queries (I am not a programer :( )

@Snapey Thank you man! I think what you mention describe well the problem, then I try to cast the id variable asi follows

public function getDataByID($id){
    $numeric_id = (int) $id;
    $curso =  Curso::where('id',$numeric_id)->first();

    if(!is_null($curso)):
      $curso_formateado =array(
                          '_id' => (string) $curso->id,
                          'clave' => $curso->clave,
                          'fecha' => $curso->fecha,
                          'titulo' => $curso->titulo,
                          'descripcion' => $curso->descripcion,
                          'video_url' => $curso->video_url,
                          'last_update' => (string) $curso->updated_at->format('U'),
                          'sede' =>  $curso->Sedes,
                        );
      return $curso_formateado;
    else:
      return $error = array('Message'=>'No existe un curso con estos datos');
    endif;
  }

I also try an horrible if inside another if

public function getDataByID($id){
    $numeric_id = (int) $id;
    if(is_numeric($numeric_id)){
      $curso =  Curso::where('id',$numeric_id)->first();
      if(!is_null($curso)){
        $curso_formateado =array(
                            '_id' => (string) $curso->id,
                            'clave' => $curso->clave,
                            'fecha' => $curso->fecha,
                            'titulo' => $curso->titulo,
                            'descripcion' => $curso->descripcion,
                            'video_url' => $curso->video_url,
                            'last_update' => (string) $curso->updated_at->format('U'),
                            'sede' =>  $curso->Sedes,
                          );
        return $curso_formateado;
      }
      else{
        return $error = array('Message'=>'No existe un curso con estos datos');
      }
    }
    else{
      return $error = array('Message'=>'El id sólo puede ser numérico');
    }

  }

unfortunately same results :(

ramjamx started a new conversation Eloquent Query Finding Similar Results

Dear Laracast community I'm trying to get an some data from a specific user, some eloquent queries I tried with poor results are:

$curso =  Curso::findOrFail($id);
$curso =  Curso::where('id',$id)->first();
$curso =  Curso::find($id);

But i'm getting the same results by trying ids "7" and "7a"

What I expect is to get a user not found when 7a is the id query, not finding some similar results as in this case when 7a id doesn't exist and instead id 7 is showing.

for more details there is the whole function.

public function getDataByID($id){

    $curso =  Curso::where('id',$id)->first();
    if(!is_null($curso)):
      $curso_formateado =array(
                          '_id' => (string) $curso->id,
                          'clave' => $curso->clave,
                          'fecha' => $curso->fecha,
                          'titulo' => $curso->titulo,
                          'descripcion' => $curso->descripcion,
                          'video_url' => $curso->video_url,
                          'last_update' => (string) $curso->updated_at->format('U'),
                          'sede' =>  $curso->Sedes,
                        );
      return $curso_formateado;
    else:
      return $error = array('Message'=>'No existe un curso con estos datos');
    endif;
  }

I may be missing some basics because im new in php and laravel anyway some light on this topic will be appreciated.

Thankyou.

03 Mar
2 years ago

ramjamx left a reply on Shutdown Homestead Entirely (MySQL, PHP, NGinx Etc.)

What OS is your host machine? have you tried MAMP for Mac or XAMP for windows? I have the exact same problem with vm's and now everything is ligher an smoth with MAMP.

You may use same laravel files installed via homestead, I just needed the step 4 on this (guide){https://telliott.io/node/969}

ramjamx left a reply on MapWithKeys Only Return One Item

I have 2 users in the DB, if I return $users directly I get 2 users, I may be using mapWithKey() in the wrong way or in the wrong context, but I tried with a foreach and same result.

ramjamx left a reply on MapWithKeys Only Return One Item

Thank you @cviv, but I'm getting the date as I need, the problem is I am getting just one value of the array.

ramjamx started a new conversation MapWithKeys Only Return One Iten

I want to change the date format in the return array of this query, but I'm getting only the last user instead all users, as if I return $users variable.

$users  = DB::table('users')->select('id',
                                    'username',
                                    'email',
                                    'name',
                                    'lastname',
                                    'factura',
                                    'acces',
                                    'registered',
                                    'last_update')
                              ->get();

  $users_formated = $users->mapWithKeys(function($user){
      $lastupdate =  strtotime($user->last_update);
      return ['_id' => $user->id,
              'username' => $user->username,
              'last_update' => (string) $lastupdate,
              ];
    });


  return $users_formated->all();

I tried with a foreach but same result :(

Any help?

ramjamx started a new conversation How To Format A Post On Discussion Forum?

Great site, I want to ask something with some code examples, but I don't know how to give code some format for better reading, I searched in facs and some formating in the discussions but I couldn't find anything related.

I can't preview my post but I'll try some markdown

    $users  = DB::table('users')->select('id',
                                    'username',
                                    'email',
                                    'name',
                                    'lastname',
                                    'factura',
                                    'acces',
                                    'registered',
                                    'last_update')
                              ->get();