dru

dru

Member Since 5 Months Ago

Experience Points
3,960
Total
Experience

1,040 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
21
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start your 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-in-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 Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • evangelist 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.

Level 1
3,960 XP
Mar
29
1 week ago
Activity icon

Replied to Npm Run Dev Not Creating Css And Js Folder With All Bundled In

Sure,

const mix = require('laravel-mix');

mix.js('resources/js/app.js', 'public/js')
   .sass('resources/sass/app.scss', 'public/css');
Activity icon

Started a new Conversation Npm Run Dev Not Creating Css And Js Folder With All Bundled In

although generally I add all those stuff manually, I'm starting a new project and i've done the following, entered this command:

php artisan ui vue --auth

then

npm install 

then

npm run dev

so as far as I understand, this should have got whats in the webpack.mix.js file and process that to compile what's in resources/js and sass to compile it into some files in the public/css and js folder.

BUT those folders or anything else has been generated. so when I enter the /login route, I can see a really ugly interface, and obviously it is so because it's not loading any of the CSS or JS..

so what could be the problem?

Mar
28
1 week ago
Activity icon

Replied to Custom Helper Not Working Correctly

we managed to get the composer version to use the latest version of php on the server and that fixed it.. but I couldn't do it because I wasn't the SUDO of the server

Mar
24
2 weeks ago
Activity icon

Replied to Custom Helper Not Working Correctly

Thanks for your reply tippin! but I'm having problems trying to use the command composer dump-autoload

it gives me this error:

Parse error: syntax error, unexpected '=' in  ........./laravel/framework/src/Illuminate/Support/Arr.php on line 384

And after searching, it's because of the php version..

so when I'm in the root directory of the app, I put php -v to check the version, it tells me it's running 7.3.15

So I've been looking for another way to do this; I also tried the command php artisan optimize:clear and still no success.

Activity icon

Started a new Conversation Custom Helper Not Working Correctly

I'm making a custom helper, so I created a file in App\Helpers\imagenCorporativa.php

then I registered in a new service provider called FuncionesServiceProvider

and in there I put in register:

public function register()
{
    //
    require_once app_path() . '/Helpers/imagenCorporativa.php';
}

Then in config\app.php

I added the provider:

App\Providers\FuncionesServiceProvider::class,

and finally the ALIAS:

 'Funciones' => App\Helpers\imagenCorporativa::class,

But I don't understand Why does it work when I test it in the routes and not in the controller.

the error that gives me is: Class 'App\Http\Controllers\Funciones' not found

Activity icon

Started a new Conversation Why Do Artisan Commands Require Database Connection Available?

I'm trying to make the command

php artisan make:command TraitMakeCommand

and for some reason it fails because I don't have the database connection available for some reason.

is there a way to circumvent this? or why is it happening if it's not even something that has to do with the database?

Feb
15
1 month ago
Activity icon

Replied to Why Dusk Testing Is Getting Reaching To Another Controller?

Hi Sinnbeck, are you sure the problem is the order of the routes? it wouldn't make sense because the test is opening a browser to specific address, so it would hit that controller specifically.

still I put the route

Route::get('/log/{token?}', 'Auth\[email protected]');

at the top and still for some reason is looking for an old controller.

I haven't listed all the routes because the project has too many routes and also, the second time the routes is pointing to the login controller is here:

Route::get('/Logout', 'Auth\[email protected]')->name('Login.logout');
Feb
14
1 month ago
Activity icon

Started a new Conversation Why Dusk Testing Is Getting Reaching To Another Controller?

I'm making some test with DUSK and in my test file I have this:

public function testBasicExample()
{
    
    $this->browse(function (Browser $browser) {
        $browser->visit('/log?token=lsdmgfnksdnfgklvsnilsenvrlken')
                ->assertSee('Fin del proyecto');
    });
}

in my routes I have this:

Route::get('/log/{token?}', 'Auth\[email protected]');

although I had one a back up of login controller called LoginController02-09-20.php, it is reaching to that old controller instead of the original one.

Then I also changed the name of the file so it wouldn't have a php extension, and still is trying to look for it.

the weird thing is, that in the server is running fine, what could be the problem?

Feb
01
2 months ago
Activity icon

Replied to Class 'App\Events\MyEvent' Not Found

FINALLY! thanks!

Activity icon

Started a new Conversation Class 'App\Events\MyEvent' Not Found

I'm trying to learn how to use pusher to have push notifications on the browser, created an account for pusher and I'm getting the error: Class 'App\Events\MyEvent' not found

the steps I did where: 1- copied all there is in the getting started tab 2- used php artisan make:event MyEvent and the file MyEvent was generated in the app\Events\ folder

3- copied there this:

<?php

use Illuminate\Queue\SerializesModels;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;

class MyEvent implements ShouldBroadcast
{
  use Dispatchable, InteractsWithSockets, SerializesModels;

  public $message;

  public function __construct($message)
  {
      $this->message = $message;
  }

  public function broadcastOn()
  {
      return ['my-channel'];
  }    

  public function broadcastAs()
  {
      return 'my-event';
  }
}

in the routes I have this: Route::get('test', '[email protected]');

in my PusherController file I have this:

  <?php 

  namespace App\Http\Controllers;

  use Illuminate\Http\Request;

  class PusherController extends Controller
  {
//
      public function test(){
    
          event(new \App\Events\MyEvent('Someone'));
      }
  }

Why is there a Class 'App\Events\MyEvent' not found error?

Jan
23
2 months ago
Activity icon

Replied to Getting Different Results In PhpMyAdmin AND Laravel With Same Query

@dalma yes it is, I thought that could have been the problem.

is there a way to make the variables in the sql string to appear? like when you to ->toSQL(); it shows you the query, but is there a way to make the :variables show the value? because I think that for some reason the value of the variable is not changing

Jan
22
2 months ago
Activity icon

Replied to Getting Different Results In PhpMyAdmin AND Laravel With Same Query

the thing is, that the result that is in phpMyAdmin is totally different.

in:

array:12 [▼
  0 => {#416 ▼
    +"eval_grupo_id": 1 //all this is wrong
    +"valor": 45.0 //all this is wrong
    +"usuarios_id": "30736" // in here it should have borught this: 30736,41659
    +"total_usuarios": 1 //it should have been: 2
  }

So I don't understand why sometimes those queries bring a diferent result if I try the query in a database tool

Activity icon

Started a new Conversation Getting Different Results In PhpMyAdmin AND Laravel With Same Query

I copy and paste the query from laravel to phpmyadmin and I get a different result, obviously it is the same database. why is this happening?

I have this code:

dump($usuario_id,$prueba_id );
        $resultados = DB::select(DB::raw('SELECT
                                smrt_preguntas.grupo_pregunta AS eval_grupo_id,
                                SUM(smrt_respuestas.puntaje) AS valor,
                                GROUP_CONCAT(DISTINCT smrt_usuarios_pruebas.usuario_id) as usuarios_id,
                                COUNT(DISTINCT smrt_usuarios_pruebas.usuario_id) as total_usuarios

                                FROM
                                    smrt_usuarios_pruebas_respuestas
                                INNER JOIN smrt_preguntas ON smrt_preguntas.id = smrt_usuarios_pruebas_respuestas.pregunta_id
                                INNER JOIN smrt_usuarios_pruebas ON smrt_usuarios_pruebas.id = smrt_usuarios_pruebas_respuestas.usuario_prueba_id
                                INNER JOIN smrt_respuestas ON smrt_usuarios_pruebas_respuestas.respuesta_id = smrt_respuestas.id
                                WHERE
                                    smrt_usuarios_pruebas.usuario_id IN ( :usuario_id )
                                    AND smrt_usuarios_pruebas.id IN ( :prueba_id )
                                    AND smrt_usuarios_pruebas.estado_id = 4
                                    AND smrt_usuarios_pruebas.activo = 1
                                    AND smrt_usuarios_pruebas.eliminado = 0
                                GROUP BY
                                smrt_preguntas.grupo_pregunta ;'),[ 'prueba_id'=>$prueba_id, 'usuario_id'=>$usuario_id ]);
    }
dd('asd', $resultados, $resultados[0]->total_usuarios);

this is the output:

"30736,41659"
"21,37"
"asd"
array:12 [▼
  0 => {#416 ▼
    +"eval_grupo_id": 1
    +"valor": 45.0
    +"usuarios_id": "30736"
    +"total_usuarios": 1
  }
  1 => {#417 ▼
    +"eval_grupo_id": 2
    +"valor": 30.0
    +"usuarios_id": "30736"
    +"total_usuarios": 1
  }
  2 => {#418 ▼
    +"eval_grupo_id": 3
    +"valor": 43.0
    +"usuarios_id": "30736"
    +"total_usuarios": 1
  }
  3 => {#419 ▶}
  4 => {#420 ▶}
  5 => {#421 ▶}
  6 => {#422 ▶}
  7 => {#423 ▶}
  8 => {#424 ▶}
  9 => {#425 ▶}
  10 => {#426 ▶}
  11 => {#427 ▶}
    ]
Jan
14
2 months ago
Activity icon

Replied to Flatting Array Not Working

YES! this finally worked!

thanks!

also, I was wondering. why flatMap wasn't working, am I using it incorrectly?

  $perfiles = collect(explode(',' , $Menu->perfil));


                    //dd($perfiles);
                    
                    $flattened = $perfiles->flatMap(function ($values) {
                        if($values !== '' ){
                            dump($values); // shows a value
                            return $values;
                        } 
                        
                    });
                    dd($flattened->all()); //is empty.
Activity icon

Replied to Flatting Array Not Working

Thanks for the suggestion, just tried it:

foreach ($menusRecorrido as $Menu){
                   
                    $perfiles = array_filter(explode(',' , $Menu->perfil));
                   
                   
                   dump(in_array($rol->rol_nivel, $perfiles)); // always false
                    if( in_array($rol->rol_nivel, $perfiles) ){
                        
                        $menus[ $Menu->posicion_id ][] = $Menu;
                    }
                    // */ 
                }
Activity icon

Replied to Flatting Array Not Working

I'm trying a new approach, as I understand, I could make a new array with arraymap.

this is my code:

$perfiles = collect(explode(',' , $Menu->perfil));
                    
                    $flattened = $perfiles->flatMap(function ($values) {
                        if($values !== '' ){
                            dump($values);
                            return $values;
                        } 
                    });
                   dd($flattened->all());

this is the output:

"0"
"10"
"20"
"50"
"100"
"1000"
"30"
"55"
"90"
"80"
"85"
"110"
"88"
[] //> dd($flattened->all()); why is this empty?? 

@bugsysha I even tried using INT with an if statement and it didn't work me well..

Activity icon

Replied to Flatting Array Not Working

in that case it allways return a false

Activity icon

Replied to Flatting Array Not Working

@nakov

when I dd($rol->rol_nivel) the output is 0 as in INT, which is right.

but there are some menues that have only:

#items: array:3 [▼
    0 => "100"
    1 => "1000"
    2 => ""
  ]

so in that it case it shouldn't be true, but after testing it a lot, all return true.

Could it be that the 2 is taken as a 0?

Activity icon

Replied to Flatting Array Not Working

@nakov

the thing is that when I only use explode, this code doesn't work well.

if( in_array($rol->rol_nivel, $perfiles) ){
    $menus[ $Menu->posicion_id ][] = $Menu;
}

And I think is because it is a multidimensional array.

Activity icon

Started a new Conversation Flatting Array Not Working

I have a string from the database that usually is something like this: 0,10,20,50,100,1000,30,55,90.

I do this:

$perfiles = collect(explode(',' , $Menu->perfil)); 
dump($perfiles);
$perfiles2 = $perfiles->flatten();
 dump($perfiles2);

the output is this:

Illuminate\Support\Collection {#332 ▼
 0 => "0"
1 => "10"
2 => "20"
3 => "50"
4 => "100"
5 => "1000"
6 => "30"
7 => "55"
8 => "90"
9 => "80"
10 => "85"
11 => "110"
12 => "88"
13 => ""
 ]}


Illuminate\Support\Collection {#419 ▼
  #items: array:14 [▼
    0 => "0"
    1 => "10"
    2 => "20"
    3 => "50"
    4 => "100"
    5 => "1000"
    6 => "30"
    7 => "55"
    8 => "90"
    9 => "80"
    10 => "85"
    11 => "110"
    12 => "88"
    13 => ""
      ]}

why isn't $perfiles2 not equal to [ 0,10, 20, 50, 100, and so on... ]

Jan
13
2 months ago
Activity icon

Started a new Conversation Confussion With Renaming Jobs Table In Laravel 6

First I ran this command:

php artisan queue:table

And that created two tables, jobs and failed_jobs, and I know that to change the name of the jobs table I have to do it in config/queue.php

But my question is. I only need to add a prefix to it, now both tables are called smrt_failed_jobs and smrt_jobs, where do I change the failed_jobs table name?

Jan
04
3 months ago
Activity icon

Replied to What Would Be The Best Way To Record Profits Per Transaction?

Hi jlrdw, thanks for the input, but I'm not planning to store credit card information, basically what I'm storing are the values/amount of the transaction and trying to keep track of profits and transaction per usage of the service.

Activity icon

Started a new Conversation What Would Be The Best Way To Record Profits Per Transaction?

I'm making a sort of service in which I'm thinking of charging a percentage per every transaction.

At first, the user needs to put credit to his account and I have a table called transaction and from there when he "uploads" money, it is registered there, and when he sends money to someone else, the transaction it is also saved in the same table.

But now, I'm thinking that to record my profits per transaction, I'm planing to have a separated table to store the percentage made in there. would that be the best approach?

any tips or advice on this?

Dec
21
3 months ago
Activity icon

Awarded Best Reply on Problem With Middleware And AUTH

All right, I found a work around.

after putting my middleware in

protected $middlewareGroups = [    
    \App\Http\Middleware\checkValidAccount::class,
    ],

    'api' => [
        'throttle:60,1',
        'bindings',
    ],
];

I was getting an error of too many redirects, so I changed the the middleware to this:

<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Support\Facades\Auth;
use Session;
use Request;
class checkValidAccount
{
/**
 * Handle an incoming request.
 *
 * @param  \Illuminate\Http\Request  $request
 * @param  \Closure  $next
 * @return mixed
 */
public function handle($request, Closure $next)
{
    
    if(Auth::check()){    
        if( (Auth::user()->profile_verified_at) ){
            return $next($request);
        }
        if(Request::path() != 'perfil/sin-verificar'){ // here I would stop the too many redirects and if it finds it is already in the right route to show me the "i need to wait till I get verified" it will simply log me out and send me to the route. 
            Auth::logout();
            return redirect('/perfil/sin-verificar');
        }
    }
    return $next($request);
    
}
}
Activity icon

Replied to Problem With Middleware And AUTH

All right, I found a work around.

after putting my middleware in

protected $middlewareGroups = [    
    \App\Http\Middleware\checkValidAccount::class,
    ],

    'api' => [
        'throttle:60,1',
        'bindings',
    ],
];

I was getting an error of too many redirects, so I changed the the middleware to this:

<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Support\Facades\Auth;
use Session;
use Request;
class checkValidAccount
{
/**
 * Handle an incoming request.
 *
 * @param  \Illuminate\Http\Request  $request
 * @param  \Closure  $next
 * @return mixed
 */
public function handle($request, Closure $next)
{
    
    if(Auth::check()){    
        if( (Auth::user()->profile_verified_at) ){
            return $next($request);
        }
        if(Request::path() != 'perfil/sin-verificar'){ // here I would stop the too many redirects and if it finds it is already in the right route to show me the "i need to wait till I get verified" it will simply log me out and send me to the route. 
            Auth::logout();
            return redirect('/perfil/sin-verificar');
        }
    }
    return $next($request);
    
}
}
Activity icon

Replied to Problem With Middleware And AUTH

I changed the middleware registration in the kernel.php file to the web

protected $middlewareGroups = [
    'web' => [
...
\App\Http\Middleware\checkValidAccount::class,
 ],
];

but it is strange because I have in my route this:

Route::post('/perfil','[email protected]')->name('unverifiedAccount');

and in the usersController I have:

public function unverifiedAccount(){
    return view('unverified');        
}

but I get a 404 error, why is that? it is like it's not reaching the controller.

Activity icon

Started a new Conversation Problem With Middleware And AUTH

I'm trying to make a middleware that is checking if the field in the user table has content to let him continue.

this middleware is registered in kernel.php under so it will always check if the user is logged in, and if it's logged in, it will check if the users is validated

protected $middleware = [
....
    \App\Http\Middleware\checkValidAccount::class,
];

this is the code:

<?php

namespace App\Http\Middleware;

use Closure;
use Auth;

class checkValidAccount
{
/**
 * Handle an incoming request.
 *
 * @param  \Illuminate\Http\Request  $request
 * @param  \Closure  $next
 * @return mixed
 */
public function handle($request, Closure $next)
{
    
    
    if(Auth::check()){
        dd(Auth::user()->profile_verified_at);
        if((Auth::user()->profile_verified_at) ){
            return $next($request);
        }else{
            return redirect()->route('unverifiedAccount');
        }
    }else{
        return $next($request);
    }
    
}
}

the thing is that in Auth::check() always returns false even if the user is logged in.

Dec
15
3 months ago
Activity icon

Replied to Error Trying To Register User

@nakov the thing is that I want to verify a user through an uploaded picture, and also that he validates his email. So I'm not that sure how to also implement that and fix the error I have now to let users register without showing the error.

Dec
13
3 months ago
Activity icon

Started a new Conversation Error Trying To Register User

I tried adding I'm getting this error:

 Argument 1 passed to Illuminate\Auth\SessionGuard::login() must implement interface Illuminate\Contracts\Auth\Authenticatable, boolean given, called in

and after googling some bit it is because I need to add this to the user class:

class User extends Authenticatable implements MustVerifyEmail
{
    use Notifiable;

I'm trying to add another field to the users table for the verified account as a timestamp. and I'd like to let people log in when both verified emails and accounts have a timestamp value, but I'm a bit lost on how to do this.

for the moment I have added the extra field to verify the account, and have done the command to generate the routes. but how could I achieve what I have explained above?

Dec
12
3 months ago
Activity icon

Replied to Getting Weird Date With Carbon

thanks, that was it! I though I had the format right.

Activity icon

Started a new Conversation Getting Weird Date With Carbon

I have extracted from the database this date: "2020-01-17 19:16:25" which is a string. and when I try to convert it to find the difference in seconds to the actual time, I get this weird output:

    $time = Carbon::createFromFormat('Y-m-d H:m:i',$time[0]->fecha_fin, 'America/Santiago'); -> this is the output   date: 2021-04-17 19:25:00.0 America/Santiago (-04:00) for some reason.

keep in mind that in app.php I have configured this

 'timezone' => 'America/Santiago',

how can I fix this to get the correct time:

dump($time->diffInDays(Carbon::now()));
Dec
10
3 months ago
Activity icon

Replied to How To Prevent The Validation Errors Showing When You Have Many Forms In A Single Page

It took me some time to understand, but I'm curious, my form is being generated by a loop, would it not be the same error bag?

I'm using this to validate:

$request = request()->validate([
      ............
]);
Dec
09
4 months ago
Activity icon

Replied to Weird Problem With Functions From Another Site

this has me stumped. I created a new class stored in App/libs/folder/pointCalculator.php

and I call it like:

$data[$key] = NivelesCultura::getInstance()->getNumber($key, $value);

and it still gives me the same undefine offset error. so aparently it is not that the variable $i inside the method obtenerNiveles is somehow global

Activity icon

Started a new Conversation Weird Problem With Functions From Another Site

I'm trying to use the same functions that someone else did to calculate points that are working correctly in another site. but when I put them in laravel, it gives me a undefined error offset, keep in mind that this functions come from a procedural style programming, which I suppose it wouldn't matter because when I put them in the controller, I add private function like in the next code:

also, the weirdest thing is that when de values in the array are higher than 28, it works, but then they are lower than 28, the functions don't work.

public function PointCalculations(){
//here is where the route calls the controller to return the values. 

$data = [ //if any value is lower than 28 it doesn't work. 
            1 =>20,
            2 =>20,
            3 =>20,
            4 =>20,
            5 =>20,
            6 =>20,
            7 =>20,
            8 =>20,
            9 =>20,
            10 =>20,
            11 =>20,
            12 =>20,
        ];
        // */
        dump($data);
        $dataPuntos = $data;
        

        foreach( $dataPuntos as $key => $value ){

            $data[$key] = $this->getNumber($key, $value);
        }
        var_dump($data);
        if($dataPuntos == NULL){
          $dataPuntos = 0;
          $data = 0;
        }
        $response = [
            "dataPuntos" =>$dataPuntos,
            "dataCirculo" =>$data,
            "type" => 'success'
          ];
          dump($response);
          dump('fin');
}



private function getNumber($block, $p){
 
    $level = array(  
        '11'    => array(17,6,4,5,3,5),
        '12'    => array(15,5,4,4,4,8), 
        '1' => array(15,5,6,5,4,5),
        '2' => array(17,6,6,5,3,3),
        '3' => array(8,4,5,5,5,13),
        '4' => array(9,4,5,5,5,12),
        '5' => array(12,4,4,5,4,11),
        '6' => array(3,2,5,5,6,19),
        '7' => array(6,2,4,4,4,20),     
        '8' => array(5,4,6,5,5,15),     
        '9' => array(3,4,5,6,6,16),     
        '10'    => array(11,4,4,5,5,11),
    );   
    $p = $p-10;     
    return $this->obtenerNivel($level[$block], $p); 
}

private function obtenerNivel($level, $p){  
    $max = count($level);
    
    for ($i=0; $i<$max;$i++){           
        $sum = $this->sum($level,$i+1);         
        if ($p <= $sum ){
             
            $data = $this->porcentajes($level);
            $r  = ($p-$data[$i-1]['T']);  //////// IT FAILS HERE; because $i = 0 so its outside the array
            $n  =  ($i * $data[$i]['Z'] + (  ($r/$data[$i]['V'])  *  $data[$i]['Z'] ) )* 100;
            return  $n;
        }
    }       
}

private function sum($level, $j){    
    $result=0;   
    $max = $j;
    for ($i=0;$i<$max;$i++){
      $result  += $level[$i];
    }
    return  $result;
} 

private function porcentajes($level){    
    $result=array();     
    $max = count($level);
    
    for ($i=0;$i<$max;$i++){          
        $result[] = array(  
            "V" =>$level[$i], 
            "T"=> $this->sum($level,$i+1), 
            "P" => ($this->sum($level,$i+1)*100)/$this->sum($level,count($level)),
            "X" => 1/$level[$i],
            "Z" => 1/count($level)
        //  "D" => 0    //(100/7)/$level[$i]            
            
        );
    }
    
    return   ($result);
}

what could be wrong in here?

Dec
08
4 months ago
Activity icon

Started a new Conversation How To Add Another Field Like Email Verified To User

I would like to add another field that if is not validated by me, the user can't log in and also he has to verify his email.

So I added a another field to the user table called: verifiedUserAt

I know there is a way to always check if the user has verified his email, but how can I also add this? would it be recommended if I added along the verified email?

making a new middleware?

Activity icon

Started a new Conversation How To Prevent The Validation Errors Showing When You Have Many Forms In A Single Page

I have a single view with many forms to update a product, but when a validation error appears, the validation error shows on all the forms, how could I prevent this from happening?

in case I need to explain better, lets say I have something like this:

<row>

    <form class="col-md-3">
    </form>

    <form class="col-md-3">
    </form>

    <form class="col-md-3">
    </form>

</row>

if I'm filling the first form and I have a validation error on the first form, that error will show on all three forms.

Dec
06
4 months ago
Activity icon

Started a new Conversation Trying To Run A Raw Query And Getting A Syntax Error 1055

I have this code:

$resultados = DB::select('SELECT
                            smrt_preguntas.grupo_pregunta,
                            SUM(smrt_respuestas.puntaje) AS valor,
                            smrt_usuarios_pruebas.usuario_id
                        FROM
                            smrt_usuarios_pruebas_respuestas smrt_usuarios_pruebas_respuestas
                        INNER JOIN smrt_preguntas smrt_preguntas ON
                            smrt_preguntas.id = smrt_usuarios_pruebas_respuestas.pregunta_id
                        INNER JOIN smrt_usuarios_pruebas smrt_usuarios_pruebas ON
                            smrt_usuarios_pruebas.id = smrt_usuarios_pruebas_respuestas.usuario_prueba_id
                        INNER JOIN smrt_respuestas smrt_respuestas ON
                            smrt_usuarios_pruebas_respuestas.respuesta_id = smrt_respuestas.id
                        WHERE
                            smrt_usuarios_pruebas.usuario_id = 1 
                            AND smrt_usuarios_pruebas.proyecto_prueba_id = 1
                        GROUP BY
                            smrt_preguntas.grupo_pregunta ;') ;
 dd($resultados);

and when it shows the error, I can copy the query and run it somewhere else and the query runs perfectly. what could be the problem?

also, there was a version where the names weren't that long, that was my latest attempt

Dec
01
4 months ago
Activity icon

Replied to How To Get Logged In Information At AppServiceProvider.php ?

Yes, your code worked! thanks! apparently when the view composer loads it is loading the session, when I tried first the IF and inside that the view composer, it wasn't loading the session until I tried the code your way.

Activity icon

Replied to How To Get Logged In Information At AppServiceProvider.php ?

So the best solution for this is making a new middleware for the view composer?

Activity icon

Replied to How To Get Logged In Information At AppServiceProvider.php ?

Yes, I thought of that too, but what I find strange is that when I log in (obviosly playing with the code to let me in), if I only use this:

View::composer(['partials.nav'],function($view){
        $notificaciones = Review::where('user_receptor', '=', Auth::user()->id )
                        ->where('visto_receptor','=',0)
                        ->get();
        $view->with('navNotif', count($notificaciones));

    });

it gets this information: Auth::user()->id

I've even tried with

if( Auth::check() ){
    ///...
}

and still gives me the auth error. but it somehow manages to work in this line:

        $notificaciones = Review::where('user_receptor', '=', Auth::user()->id )
Activity icon

Started a new Conversation How To Get Logged In Information At AppServiceProvider.php ?

I made a view composer at AppServiceProvider that searchs for users notification and to prevent crashing from non logged users I have it "protected" with an IF like:

if(Auth::user()->id ){    
        View::composer(['partials.nav'],function($view){
            $notificaciones = Review::where('user_receptor', '=', Auth::user()->id )
                            ->where('visto_receptor','=',0)
                            ->get();
            $view->with('navNotif', count($notificaciones));

        });
        
    }

but it gives me an error:

Trying to get property 'id' of non-object

How can I make it work and not crash if someone is not logged in

Nov
29
4 months ago
Activity icon

Replied to Add Minutes To Time Stored In A Database

OOOOOOOOOHHH! that was driving me insane! and how can I see if it added the time correctly?

Activity icon

Replied to Add Minutes To Time Stored In A Database

I have no idea why it looked like that, I almost was sure it was ok:

here it is:

$id->reservas =    '2019-12-01 15:58:28'; // this is an example of whats stored in the database. 
foreach( $id->reservas as $reserva){
        $mins = str_replace(' Mins.','',$id->tiempo_maximo);
        dump($mins);
        dump(Carbon::parse($reserva->fecha_reserva))->addMinutes( intval($mins) ); // ->but here is not adding the minutes
    }
Activity icon

Started a new Conversation Add Minutes To Time Stored In A Database

I'm using this code:

$id->reservas =    '2019-12-01 15:58:28'; // this is an example of whats stored in the database. 
foreach( $id->reservas as $reserva){
            $mins = str_replace(' Mins.','',$id->tiempo_maximo);
            dump($mins);
            dump(Carbon::parse($reserva->fecha_reserva))->addMinutes( intval($mins) ); // ->but here is not adding the minutes
    }

why isn't it adding minutes?

Nov
26
4 months ago
Activity icon

Replied to What Is The Best Way To Handle An App That Has Tests, Questions, Answers And The Solution To That Answere

OH! some of these points are too advanced, where would I write the solution class?

if I do eager loading, do I still have to make the relationships in the model?

are there ways to make some defaults custom field names in the models like $foreign_key = 'usuario_id' ?

what prior configuration in the model do I have to make to have this working?

    $user = User::with(['tests.questions.answers', 'answers.question.test']])->find($userId);

how does laravel chooses the table with this? 'tests.questions.answers' , what does that exactly means?

sorry for the inconveniences

Nov
25
4 months ago
Activity icon

Replied to What Is The Best Way To Handle An App That Has Tests, Questions, Answers And The Solution To That Answere

great insight

I'm also making a pivot table with the answer of the user, because the anwser of the question is so it can be a selection type.

so, I'm also assuming I have to do the same with the user model, adding a function like:

public function tests(){
    returh $this->hasManyThrough(Test::class, Question::class, Answer::class );
}

could that work? or the many through is only between two tables, so I would need to make another function for questions and for answers?

btw, this is my users_tests_answers table:

PK  id
FK1 prueba_id
FK2 usuario_id
FK3 tipo_prueba_id
FK4 prueba_id
respuesta_id
respuesta_text
fecha_creacion
fecha_update
activo
aprobado
Activity icon

Started a new Conversation What Is The Best Way To Handle An App That Has Tests, Questions, Answers And The Solution To That Answere

For the moment I have a table named TESTS, then another called questions that is related to test with test_id, then I have another with answers that is related to questions with question_id and so on.

so, in the models I'm making are, one model for tests, one for questions, one for answere, and so on.

Inside Tests I have a relationship:

public function questions(){
    return $this->hasMany('App\Question');
}

in the questions relationship I have

public function answers(){
    return $this->hasMany('App\Answers');
}
public function tests(){
    return $this->belongsTo('App\Test');
}

and so on...

now, the thing is that some of these test could have by the very least 120 questions.

how could I make a good relationship to bring the user and his answeres with questions and all info related to a test in a fast manner? (the user model hasn't been touched)

should I have the user model with a function of test, questions, answers? or is it possible to have one function that brings all that information related to a test?

Nov
24
4 months ago
Activity icon

Replied to Adding A Class To Laravel

thanks! this was it!