tyteck

Web developper senior at Aspremont

Member Since 1 Year Ago

Experience Points
13,380
Total
Experience

1,620 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
128
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.

Level 3
13,380 XP
Oct
06
1 week ago
Activity icon

Replied to SFTP Storage And Public Permissions

by the way I fixed it doing

Storage::disk('sftp')
                ->put(
                    $this->thumbToSend->relativePath(), // => folderToCreate/file.jpg
                    $this->thumbToSend->getData()
                );
            Storage::disk('sftp')
                ->setVisibility('folderToCreate', 'public');

in filesystems.php

'visibility' => 'public',
'permPublic' => 0755,

Thanks anyway :)

Activity icon

Replied to SFTP Storage And Public Permissions

Hi everyone. I've the same kind of problem as you and I've done what you suggest.

'visibility' => 'public',
'permPublic' => 0755,

Files are uploaded and set to rwxr-xr-x but folder where the file is located is not. I'm doing

Storage::disk('sftp')
                ->put(
                    $this->thumbToSend->relativePath(), // => folderToCreate/file.jpg
                    $this->thumbToSend->getData() 
                );

I've added some tries of setVisibility but folder is still created with 644 (rw-r--r--). Is there a way to fix that ?

Sep
14
1 year ago
Activity icon

Replied to UpdateOrCreate Summing Previous Column Value

@Cronix I was fearing one answer this kind.

@D9705996 I will try this solution

Thanks for your answers.

Activity icon

Started a new conversation UpdateOrCreate Summing Previous Column Value

Hi guys The Eloquent doc is giving this example for updateOrCreate .

$flight = App\Flight::updateOrCreate( ['departure' => 'Oakland', 'destination' => 'San Diego'], ['price' => 99] );

Now I want that price increase by 10. Is there a way to do

$flight = App\Flight::updateOrCreate( ['departure' => 'Oakland', 'destination' => 'San Diego'], ['price' => 'price' + 10] );

Il would like to reproduce INSERT INTO trip (departure, destination, price) VALUES ('Oakland', 'San Diego', 99) ON DUPLICATE KEY UPDATE price = price + 12

Here is my export for this dummy example.

CREATE TABLE `trip` (
  `departure` varchar(20) NOT NULL,
  `destination` varchar(20) NOT NULL,
  `price` int(3) UNSIGNED NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Index for table `trip`
--
ALTER TABLE `trip`
  ADD UNIQUE KEY `foo` (`departure`,`destination`);
COMMIT;

First query INSERT INTO trip (departure, destination, price) VALUES ('Oakland', 'San Diego', 99) ON DUPLICATE KEY UPDATE price = price + 12 My price is 99.

Second query INSERT INTO trip (departure, destination, price) VALUES ('Oakland', 'San Diego', 99) ON DUPLICATE KEY UPDATE price = price + 12 My price is 111.

Yes This example is nonsense it's only for the beauty :) Thanks for any help

Sep
13
1 year ago
Activity icon

Replied to Using Destructor In Eloquent

I'm generating some static elements for my customers and I'm generating those every hour.

Actually my longest script duration is barely one minute long but I want to track the script execution time in order to be able to react if duration is coming nearby 1H long (perhaps one day) or if one script duration grow strangely.

Sorry for my english and thanks from France :)

This is for my back office only and I'm already using the great Laravel debugbar :)

Activity icon

Started a new conversation Using Destructor In Eloquent

Hi guys.

I'm currently refactoring some legacy part of my app that contain many console scripts. To keep measure of time taken by one script run I was using one single class. The class was containing only one constructor and destructor.

The constructor was keeping the script name and the startTime. The destructor was getting the duration and writing it in the database.

In my scripts the only thing I had to do was to instantiate this class with the script filename. At the end of the script the destructor was making its job all alone.

Now I'm trying to use Eloquent (without Laravel) and it seems there is no explicit __destruct so it make me asking you what would be the good way to make the same mechanism on a new MVC model.

I followed the jeff_way lesson about that https://laracasts.com/lessons/how-to-use-eloquent-outside-of-laravel.

Thanks for any advice :)

Aug
27
1 year ago
Activity icon

Replied to Is There A Reason Why Dd/var_dump/die Event Exit Doesn't Work Anymore

Ok. My problem was that I was opening WSL/Linux/Ubuntu files from my Windows VsCode as a normal windows file. Don't do that.

The better way to do that is kind of strange but it works.

On the WSL - install open ssh server and from windows access it with "putty" or "sftp net drive" and suddenly dd and var_dump and exit is working properly :)

Here is a link to make it clearer

https://superuser.com/questions/1111591/how-can-i-ssh-into-bash-on-ubuntu-on-windows-10/1114162#1114162

Activity icon

Replied to Is There A Reason Why Dd/var_dump/die Event Exit Doesn't Work Anymore

I will check that, by the way there is problems using WSL like I do. They told it to me ... Do not change linux files using windows apps ... https://blogs.msdn.microsoft.com/commandline/2016/11/17/do-not-change-linux-files-using-windows-apps-and-tools/

Guess what I was doing ? :) Thanks for your help.

Activity icon

Replied to Is There A Reason Why Dd/var_dump/die Event Exit Doesn't Work Anymore

Everything commented and still the same issue ... I will check a cache problem dd_still_not_working.jpg

Activity icon

Replied to Is There A Reason Why Dd/var_dump/die Event Exit Doesn't Work Anymore

Here is my composer.json extract

"require": {
        "php": ">=7.0.0",
        "laravel/framework": "5.6.*",
        "laravel/tinker": "~1.0",
    ...
Activity icon

Replied to Is There A Reason Why Dd/var_dump/die Event Exit Doesn't Work Anymore

Yes anything else work. Artisan is working, Tinker too. ... it is the first time I encounter that kind of bug ...

Activity icon

Replied to Is There A Reason Why Dd/var_dump/die Event Exit Doesn't Work Anymore

here is a screenshot dd_not_working.jpg I installed Laravel with composer.

Activity icon

Started a new conversation Is There A Reason Why Dd/var_dump/die Event Exit Doesn't Work Anymore

Hi guys. I format an old laptop and installed windows 10 on it. Then I installed WSL Ubuntu (windows 10 bash). I installed Laravel (of course) and everything seamed fine til I met one bug. When I tried to debug it I was surprised to see that neither dd or var_dump or even exit was working. I've googled for a solution but didn't found it. Do you have an idea ?

Jun
07
1 year ago
Activity icon

Replied to Many Models Used To Display On One Page

I would like to display "most popular cats/dogs names" on the same page.

Your answer seems fine to me. I will try that :)

Jun
06
1 year ago
Activity icon

Started a new conversation Many Models Used To Display On One Page

Hi there.

I can't find this answer to this simple question.

Admit I have 2 models (cats & dogs).

I have one controller to index/update/show/store for each model.

Now I would want to have a page where both models are displayed.

One column cats, one columns dogs.

How to do that ? Do I need to create a specific controller ? A specific model ?

Thanks by advance.

May
20
1 year ago
Activity icon

Replied to Migration And Update One Table Column From Another Table Column

I found my own answer so here it is

DB::table('table1')->join('table2', 'table1.id', '=', 'table2.foreign_key')->update(['table1.column1'=>DB::raw('table2.column8')]);

A little bit of context here. I had 2 tables that were joined with a string column. That was a bad idea.

So I added a autoincrement id in the table 2. Then I added a numeric column to table 1. All I had to do was to report the numeric id from table 2 in table 1 on the old join to do the trick.

I searched on many posts here and on stack without finding a solution approching. This one is a mix that is pretty clear.

If you need more information please ask :)

Activity icon

Replied to Where Are You All From?

Aspremont (Near Nice), France ! :)

May
17
1 year ago
Activity icon

Started a new conversation Migration And Update One Table Column From Another Table Column

Hi there

The query I need to do is quite simple the MySQL way.

update table1, table2 set table1.column1 = table2.column8 where table1.id=table2.foreign_key

But I would like to do the same query using Laravel Eloquent model ? How do you do this ?

Apr
29
1 year ago
Activity icon

Replied to How To Filter 2 Tables - Cats And Dogs

Thanks for your answer Vilfago, it helped me to understand scopes.

Here is the solution I'm currently using.

In the cats model (app/cats.php)

public function scopeBornBetween($query, $value)
    
    {

        return $query->whereBetween('birthday', [$value[0], $value[1]]);

    }

The same in the dogs model (app/cats.php).

It works but I bet there is a better way to do so. Using global scope ?

If I improve this solution I will write it here.

Activity icon

Started a new conversation How To Filter 2 Tables - Cats And Dogs

Hi there

By the way I'm stuck on one problem.

Admit I've 2 tables which are similar. Say cats and dogs.

Cats is migrated like this

class CreateCatsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('cats', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name');
            $table->date('birthday');
            $table->boolean('alive');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('cats');
    }
}

Dogs is migrated the same way (replace cats by dogs).

I have make a controller to interact with the cats table and a controller to interact with the dogs table.

The cats controller is like this

class CatsController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {

        $cats = cats::all();

        return view('cats.index', compact('cats'));

    }
}

The route (routes/web.php) to look at those cats is like this

/**
 * cats routing
 */
Route::resource('cats', 'CatsController');

/**
 * dogs routing
 */
Route::resource('dogs', 'DogsController');

/**
 * all pets routing
 */
Route::get('/', '[email protected]');

Now my point is that I want to see some cats & dogs selection on my index page.

So I've added a new controller.

class CatsAndDogsController extends Controller
{
    public function index() {

        $cats = cats::all();
        
        $dogs = dogs::all();

        return view('index', compact('cats', 'dogs'));

    }
}

But, what I really want is to filter these informations.

For example I would want to get allthe the pets that are alive and all the pets that are alive and born on a certain date. How may I do that with laravel ?

Feb
12
1 year ago
Activity icon

Replied to Policy Not Parsed

thanks for your reply. By the way not ... it didn't blow away (and I'm sad of it).

how can I test my policy is really being used ?

Feb
11
1 year ago
Activity icon

Started a new conversation Policy Not Parsed

Hi there

My problem is that my policy seems not to be read once registered. To be sure I even wrote a syntax error and nothing happens.

my model is app\medias_stats.php

my policy app\Policies\MediasStatsPolicy.php

namespace App\Policies;

use App\User;
use App\medias_stats;
use Illuminate\Auth\Access\HandlesAuthorization;

I hate you not been read !

class MediasStatsPolicy
{
    use HandlesAuthorization;

    /**
     * Determine whether the user can view the mediasStats.
     *
     * @param  \App\User  $user
     * @param  \App\medias_stats  $mediasStats
     * @return mixed
     */
    public function view(User $user, Channel $mediasStats)
    {
        return true;
    }   
}

my auth provider app\Providers\AuthServiceProvider.php

namespace App\Providers;

use Illuminate\Support\Facades\Gate;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;

use App\medias_stats;
use App\Policies\MediasStatsPolicy;

class AuthServiceProvider extends ServiceProvider
{
    /**
     * The policy mappings for the application.
     *
     * @var array
     */
    protected $policies = [
        //'App\Model' => 'App\Policies\ModelPolicy',
        medias_stats::class => MediasStatsPolicy::class,
    ];

    /**
     * Register any authentication / authorization services.
     *
     * @return void
     */
    public function boot()
    {
        $this->registerPolicies();
    }
}

As I understood the policy, once registered it should parse the MediasStatsPolicy... and explode with a big syntax error ('I hate you not been read !') but no.

What did I miss ?

Dec
10
1 year ago
Dec
08
1 year ago
Activity icon

Replied to Logged Out After Register And Login In Laravel 5.5

log was telling

[2017-12-07 11:24:40] dev.INFO: App\Http\Controllers\Auth\RegisterController::App\Http\Controllers\Auth\RegisterController::create
[2017-12-07 11:24:41] dev.INFO: User is connected
[2017-12-07 11:24:41] dev.INFO: App\Http\Controllers\HomeController::App\Http\Controllers\HomeController::__construct

I would love that to work ... but it is not the case :(

Dec
07
1 year ago
Activity icon

Replied to Logged Out After Register And Login In Laravel 5.5

I moves the check in the index function but it seems the $this->middleware('auth'); redirect me on the login form before I can access the home.

My dreamed process

  • validator (this is ok)
  • create (this is ok)
  • login (this is ok)
  • redirect on the new user new home (this is the problem) I'am redirect on the login form.
namespace App\Http\Controllers;

use Illuminate\Support\Facades\Log;

use Illuminate\Http\Request;
use Session;

/**
 * the channel controller class.
 * 
 */
class HomeController extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        Log::info(__CLASS__.'::'.__METHOD__);
        $this->middleware('auth');
    }

    /**
     * Show the application dashboard.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        Log::info(__CLASS__.'::'.__METHOD__);
        if(auth()->check()){
            Log::info('user is connected : '.auth()->user()->name);            
        } else {
            Log::info("not connected user :( ! ");
        }

        return view('home');
    }
}

Notice that if I use the login form with the new account all is ok and my new user can access its "home".

thanks for any help

Dec
06
1 year ago
Activity icon

Started a new conversation Logged Out After Register And Login In Laravel 5.5

Hi there. I'm new to Laravel and I'm stuck on a login problem I don't understand. I want a new subscriber to be logged in after registration. I am using the artisan make:authto authenticate users.

The registration works well but right after the redirection, the user appear t be logged out. here is my registerController

namespace App\Http\Controllers\Auth;

use App\User;
use App\Http\Controllers\Controller;

use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Log;

use Illuminate\Auth\Events\Registered;
use Illuminate\Foundation\Auth\RegistersUsers;
use Illuminate\Http\Request;


class RegisterController extends Controller
{
   
    use RegistersUsers;

    protected $redirectTo = '/home';

    /**
     * Mailchimp service provider
     *
     * @var object mailchimp instance
     */
    protected $mailchimp;

    /**
     * mailchimp list id for  PodMyTube Users
     *
     * @var string
     */
    protected $listId = '-----------';        // Id of newsletter list

    public function __construct(\Mailchimp $mailchimp)
    {
        $this->middleware('guest');

        $this->mailchimp = $mailchimp;
    }

    protected function validator(array $data)
    {
        Log::info(__CLASS__.'::'.__METHOD__);
        $data2valid = [
            'name' => 'required|string|max:255',
            'email' => 'required|string|email|max:255|unique:users',
            'password' => 'required|string|min:6|confirmed'
        ];

        if(env('APP_ENV') != 'dev'){
            $data2valid['g-recaptcha-response'] = 'required|captcha';
        }
        
        return Validator::make($data, $data2valid);
    }


    protected function create(array $data)
    {
        Log::info(__CLASS__.'::'.__METHOD__);

        $this->addEmailToList($data['email']);

        
        return User::create(
            [
                'name' => $data['name'],
                'email' => $data['email'],
                'password' => bcrypt($data['password']),
            ]
        );
    }


    public function register(Request $request)
    {
        Log::info(__CLASS__.'::'.__METHOD__);

        // validating form data
        $this->validator($request->all())->validate();

        // create user in DB
        $user = $this->create($request->all());
        
        // login the user newly created 
        Auth::login($user);
        
        
        if(Auth::check()){
            Log::info('User is connected');            
        } else {
            Log::info('SHIT !');
        }

        // redirect
        return redirect()->route('home');

    }


    public function addEmailToList($email)
    {
        try {
            $this->mailchimp->lists->subscribe($this->listId, ['email' => $email]);
        } catch (\Mailchimp_List_AlreadySubscribed $e) {
            // do something
        } catch (\Mailchimp_Error $e) {
            // do something
        }
    }
}

and here is my homeController

<?php
namespace App\Http\Controllers;

use Illuminate\Support\Facades\Log;

use Illuminate\Http\Request;
use Session;

class HomeController extends Controller
{
    public function __construct()
    {
        Log::info(__CLASS__.'::'.__METHOD__);
        if(auth()->check()){
            Log::info('User is connected');            
        } else {
            Log::info('SHIT !');
        }
        $this->middleware('auth');
    }

    /**
     * Show the application dashboard.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        Log::info(__CLASS__.'::'.__METHOD__);
        return view('home');
    }
}

When I read the logs I got

[2017-12-06 21:32:46] dev.INFO: App\Http\Controllers\Auth\RegisterController::App\Http\Controllers\Auth\RegisterController::create
[2017-12-06 21:32:47] dev.INFO: User is connected
[2017-12-06 21:32:47] dev.INFO: App\Http\Controllers\HomeController::App\Http\Controllers\HomeController::__construct
[2017-12-06 21:32:47] dev.INFO: SHIT !

If someone can explain me why the newly registered/logged user is suddenly not connected I would be grateful :)