brakkar

brakkar

Member Since 2 Years Ago

Experience Points 10,840
Experience Level 3

4,160 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 96
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.

23 Mar
2 years ago

brakkar started a new conversation Return Value Of Delete Method

Hello, the return value of a query builder delete method return an int. Is this int "1" on successful delete, and "0" otherwise ?

17 Mar
2 years ago

brakkar started a new conversation Cascade Delete Of A Many To Many Relation Table

Hi, let's say I have 3 tables

  • contacts
  • events
  • tags

and a table for relations:

  • taggable, with fields: tag_id, taggable_id and taggable_type

This is the kind of structure shown in laravel documentation.

Correct me if i'm wrong: the taggable_id field is not a real foreign key field. Thus, how is the record supposed to be deleted since it can't benefit from cascade delete ? Should we do it manually ?

14 Mar
2 years ago

brakkar started a new conversation By What Magic Can I Use The Helpers Methods Outside Laravel ?

I use eloquent outside laravel. Today I needed to slugify a string, so my ide gave me a hint of a 'str_slug'. I thought that this could be a new php 7 feature. I checked in google and realized it is in fact a laravel helper. What a nice surprise.

By what magic are all the helpers method of laravel, available on a project using eloquent only ? I mean, the file doesn't even 'use' anything related to eloquent yet all the method are available and working. How ?

brakkar left a reply on Db Transaction: What If Server Crashes In The Middle Of A Transaction ?

Greg, thanks for the interesting answer. SQL is really a great technology.

13 Mar
2 years ago

brakkar left a reply on Db Transaction: What If Server Crashes In The Middle Of A Transaction ?

Okay. Does the log gets automatically pruged after a while ? For example, the server crashes, so there was no chance to commit or rollback, and the data in the log about that transaction is not needed anymore and won't be called.

brakkar left a reply on Db Transaction: What If Server Crashes In The Middle Of A Transaction ?

Hello, just another question out of pure curiosity: where is the temporary data of the queries stored, that kind of table copy you mention ? And how it decides when to purge temp data in case of a server crash in middle of transaction as mentionned above ?

brakkar started a new conversation Transaction Doesn't Work When Instantiating Eloquant From A Class

I try to use transactions OUTSIDE laravel. it works when I include the db instantiation right in my index file as is:

use Illuminate\Database\Capsule\Manager as Db;



$db = new Db;

$db->addConnection( [
    'driver'    => Settings::DATABASE_DRIVER,
    'host'      => Settings::DATABASE_HOST,
    'database'  => Settings::DATABASE_NAME,
    'username'  => Settings::DATABASE_USERNAME,
    'password'  => Settings::DATABASE_PASSWORD,
    'charset'   => 'utf8',
    'collation' => 'utf8_unicode_ci',
    'prefix'    => ''
] );

# Make this Capsule instance available globally via static methods... (optional)
$db->setAsGlobal();

I can then elsewhere use code like this:

Db::connection()->beginTransaction();

# Create blog post in the database and return its id
$blogPostRecordId = ( new BlogDbModel() )->create( $_POST );
Db::connection()-> rollBack();

it will correctly work and rollback back.

However, If I get an instance of the db from a class, it won't work:

class DbSql
{

    /**
     * Use the eloquent query builder and orm. Bypass PDO interface.
     * @return Capsule
     */
    public function db()
    {
        $capsule = new Capsule;

        $capsule->addConnection( [
            'driver'    => Settings::DATABASE_DRIVER,
            'host'      => Settings::DATABASE_HOST,
            'database'  => Settings::DATABASE_NAME,
            'username'  => Settings::DATABASE_USERNAME,
            'password'  => Settings::DATABASE_PASSWORD,
            'charset'   => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix'    => ''
        ] );

        # Make this Capsule instance available globally via static methods... (optional)
        $capsule->setAsGlobal();

        // Setup the Eloquent ORM... (optional; unless you've used setEventDispatcher())
        //$capsule->bootEloquent();


        return $capsule;
    }
}

and then use

( new DbSql() )->db()->getConnection()->beginTransaction();

# Create blog post in the database and return its id
$blogPostRecordId = ( new BlogDbModel() )->create( $_POST );
( new DbSql() )->db()->getConnection()->rollBack();

it simply won't work and the transaction is ignored. Why does getting the db instance from a class instantiation make the process fail ?

12 Mar
2 years ago

brakkar left a reply on Proper Way To Format A Many To Many Query With The Query Builder

Turns out to be:

 $query = ( new DbSql )->db()->table( 'blog_posts' )
            ->join( 'model_names_relations', 'blog_posts.id', '=', 'model_names_relations.blog_post_id' )
            ->join( 'model_names', 'model_names.id', '=', 'model_names_relations.model_name_id' )
            ->where( 'blog_posts.id', '12' )
            ->select('model_names.name')
            ->get();

brakkar started a new conversation Outrageous Captcha Verification

I've been controlled by the recatpcha robot like 5 times almost in a row after I posted a topic, and noticed some typos I quickly wanted to correct. This is extremely annoying especially since the image recognition challenge is particularly difficult. After i've been controlled ONCE, what risk there is that i'll tranform into a spamming robot withing the next 30 minutes ? Seriously, please, do something about that.

(i've suffered 2 controls again when i clicked that "i'm not a robot" before posting thig topic. So I had to resolve SEVEN recaptcha challenge in a few minutes. That's crazy.).

brakkar started a new conversation Proper Way To Format A Many To Many Query With The Query Builder

Hello, i'm trying to build a query with the query builder only (NOT the full eloquent) used outside laravel.

Here is the context:

A blog post can be about several models (like a top model). And a model can belong to several blog post.

Table: model_names
This table contains 2 models each with 2 fields:
**id**: 1. **Name**: Brenda
**id**: 3. **Name**: Lucia
Table: blog_posts
This table contains a post with 2 fields:
**id**: 12. **blog_title**: This is a title
Table: model_names_relations (holding the many to many foreign keys ids of the other 2 tables).
Contains 2 relations:
**id**: 1. **blog_post_id**: 12. **Model_name_id**: 3
**id**: 2. **blog_post_id**: 12. **Model_name_id**: 1

So as you can see, the blog post has a relation to 2 models.

My goal is to build a query, so that given a model id ( 12 in this case) will return related models names (Brenda and Lucia in this case). So I want the result of the query to be ultimately "Brenda" "Lucia"

How to achieve this with the query builder? I guess I should use joins ?

brakkar left a reply on Db Transaction: What If Server Crashes In The Middle Of A Transaction ?

What if I need intermediate value returned from the inserts, to be used by next insert for example, but still preserve the benefit of the transaction ?

brakkar started a new conversation Db Transaction: What If Server Crashes In The Middle Of A Transaction ?

Hi, I'm new to DB transactions. Let's imagine this hypothetical case:

// Start transaction!
DB::beginTransaction();

complex code operation + database insert 1
complex code operation + database insert 2

REAL LIFE POWER FAILURE

complex code operation + database insert 3



DB::commit();

You see that the power failure interrupted the process before the commit() . Yet the flow made 2 inserts in the database. What will happen to these inserts ? At no point did I specified a rollback. So will the 2 first inserts be preserved in the db ?

14 Feb
2 years ago

brakkar started a new conversation Php Includes And Namespace And Use Statements

Hello, let's say I have a script A with its own namespace and use statements on top. Now in the middle of it, I include a script B with its own namespace and uses statements.

it works fine, yet PHP doesn't like to have includes and uses statements that are not on top of the script, which should be the case on the location of the included script. Behind the scene how does php treat such included scripts ?

10 Feb
2 years ago

brakkar left a reply on Socialite: InvalidStateException In AbstractProvider.php

I had this error because I was accessing my local site from the local ip instead of localhost. You should use localhost if that was is set on facebook as authorized url.

07 Feb
2 years ago

brakkar started a new conversation Strategy For Getting Flash Messages Out Of The Template Context

Hello, I will implement a full page caching for some very busy part of my site, still I would like to be able to use flash messages.

Correct me if i'm wrong, I won't be able to do so with standard implementation since flash messages are built in the templates, and caching a page while a message is displayed would be served to all subsequent requests.

Is anyone aware of a system to do what I want ? Accessing flash messages but from javascript I guess ?

Or would implementing it like this would be a possible way to do it: Replace each flash message by the creation of a cookie to hold those message. Have a javascript check the cookie on each page load to see if it contains a flash message, and if so, display it. Have the message deleted from the cookie with a time interval or from a middleware if that is possible... this will need R&D.

Please advise if you have experience with this problematic.

brakkar started a new conversation Named Route + Parameter

Hi, I have in an email a path to a route:

{{ URL::to('user/password-confirm/' . $passwordResetRecordFinal['token']) }}

Is it possible to replace this by the name of the route ? (let's say the same is 'passConfirm'). I'm not sure if it is possible to add the variable $passwordResetRecordFinal['token'] to a named route.

06 Feb
2 years ago

brakkar started a new conversation Lumen And Laravel Sharing Same Db

Hello, Is this kind of setup doable:

..sever 1: laravel

..server2: mysql

..servers 3: lumen

Server 1 would serve web site with template and all. Server 3 would be only for serving json api. Both server sharing a same database from server 2.

So can both lumen read and write to a same db? The idea is to have full stack server 1 for web and fast api for various mobile devices.

brakkar left a reply on Manage Composer Dependencies For Laravel Update And Git

I'm interested in this also. Is your vendor directory tracked by the git repository, or is it excluded ?

03 Feb
2 years ago

brakkar left a reply on Can't Save User With A Certain Method

OK thank you for your answer. Is there a similar way to check for field (in this case confirmation_code) but return a real user instance ?

brakkar started a new conversation Can't Save User With A Certain Method

Hi,

why does this work:

$user2 = auth()->user();
$user2->confirmed = 1;
$user2->confirmation_code = Null;
$user2->save();

But this doesn't:

$user = DB::table( 'users' )->where( 'confirmation_code', $confirmationId )->first();
$user->confirmed = 1;
$user->confirmation_code = Null;
$user->save();

It won't save and throw an exception on save.

Call to undefined method stdClass::save()

Aren't these 2 user instances ?

brakkar left a reply on It Just.... Doesn't Work (valet)

Could someone please post the content of their /Users/ME/.valet/valet.sock file ?

I will try to create it manually and see how it goes.

brakkar left a reply on Mandatory Migrations ?

That depends what you do down the road?

For example, could laravel upgrade to newer version go wrong if your database change are not reflected in the migrations ? Did it ever happened that something broke because ignoring migration system and doing db things from external tool ?

02 Feb
2 years ago

brakkar left a reply on How Requests Transmits Cookie Information ?

Ok so it's the cookie content that gets transferred, not the physical file if what I understand is correct?

brakkar started a new conversation How Requests Transmits Cookie Information ?

Hi, this is a general php and web question.

Once a cookie is set by the server response into the user browser, on subsequent request, does the browser sends back to the server the physical cookie file, or just the session id in the header, or even something else ?

01 Feb
2 years ago

brakkar left a reply on Old Values Not Displaying

Khaled, thanks a lot for the code. Got it working. What an amazing support group guys.

brakkar left a reply on Old Values Not Displaying

Yes, i'm using chrome also.

brakkar left a reply on Old Values Not Displaying

Guys, it's all working now. I restarted the entire computer and local servers. Seems there was something messing up upon form submission with clearing the fields. Sorry I should have done that much much earlier computer is being one since several days.

brakkar left a reply on Old Values Not Displaying

A note: when the form validates, it correctly pass value to create the record in the database. So the problem seems specificaly with invalidation.

For some reason, your latest example IS working !! Thank you so much.

brakkar left a reply on Old Values Not Displaying

Here are all the routes, with directory capitalized. I haven't touched or created any js:

Route::get( '/', 'base\[email protected]' )->name('home');


#------------------------------------------------------------------------------------
# Users
#------------------------------------------------------------------------------------
Route::get('/user/login', 'Users\[email protected]');

Route::get( '/user/register', 'Users\[email protected]' )->name( 'registerget' );
Route::post( '/user/register', 'Users\[email protected]' )->name( 'registerpost' );

brakkar left a reply on Old Values Not Displaying

array:4 [▼
  "_token" => "IIZcvyxqKwI7WrQ6YKXEqq6NAszLNIps7UvEjAYZ"
  "username" => null
  "email" => null
  "password" => null
]

brakkar left a reply on Old Values Not Displaying

Okay, did so. Problem persists.

brakkar left a reply on Old Values Not Displaying

Jaytee, indeed changing the post route didn't resolve the problem.

brakkar left a reply on Old Values Not Displaying

Sure, here is registration.blade.php

REGISTRATION
<br/>


{{--@if ($errors->count())--}}
    {{--{{ dd(request()) }}--}}
{{--@endif--}}

<form method="post" action="/user/register">
    {{csrf_field() }}
    username:<br>
    <input type="text" name="username" value="{{ old('username') }}"><br/>
    @if ($errors->first('username'))
        <li>
            {{ $errors->first('username')  }}
        </li>
    @endif
    <br><br>


    Email:<br>
    <input type="email" name="email" value="{{ old('email') }}"><br/>
    @if ($errors->first('email'))
        <li>
            {{ $errors->first('email')  }}
        </li>
    @endif
    <br><br>

    password:<br>
    <input type="password" name="password" value="{{ old('password') }}">
    @if ($errors->first('password'))
        <li>
            {{ $errors->first('password')  }}
        </li>
    @endif
    <br><br>
    <button type="submit"> SUBMIT FORM</button>
</form>
{{ dump(session()->all(), old()) }}

brakkar left a reply on Old Values Not Displaying

array:5 [▼
  "_token" => "IIZcvyxqKwI7WrQ6YKXEqq6NAszLNIps7UvEjAYZ"
  "_previous" => array:1 [▼
    "url" => "http://localhost:8000/user/register"
  ]
  "_flash" => array:2 [▼
    "old" => array:2 [▼
      0 => "_old_input"
      1 => "errors"
    ]
    "new" => []
  ]
  "_old_input" => array:4 [▼
    "_token" => "IIZcvyxqKwI7WrQ6YKXEqq6NAszLNIps7UvEjAYZ"
    "username" => null
    "email" => null
    "password" => null
  ]
  "errors" => ViewErrorBag {#155 ▼
    #bags: array:1 [▼
      "default" => MessageBag {#156 ▼
        #messages: array:3 [▼
          "username" => array:1 [▼
            0 => "The username field is required."
          ]
          "email" => array:1 [▼
            0 => "The email field is required."
          ]
          "password" => array:1 [▼
            0 => "The password field is required."
          ]
        ]
        #format: ":message"
      }
    ]
  }
]
array:4 [▼
  "_token" => "IIZcvyxqKwI7WrQ6YKXEqq6NAszLNIps7UvEjAYZ"
  "username" => null
  "email" => null
  "password" => null
]

brakkar left a reply on Old Values Not Displaying

Jaytee, the project is really new i've been following tutorials and haven't touched any setting except the mysql ones. I did a few migration, modified a bit the User model. I didn't changed session or touched anything about session. Maybe they are disabled ?

brakkar left a reply on Old Values Not Displaying

Khaled, thanks for code:

Type error: Argument 1 passed to Illuminate\Validation\Factory::make() must be of the type array, object given, called in /Users/ME/Documents/Apps_And_Sites/PHP_Apps/rib/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php on line 221

brakkar left a reply on Old Values Not Displaying

Jaytee old values are all 'null' !!

brakkar left a reply on Old Values Not Displaying

Thanks Khaled but I need to do it manually. Also in your example, $data cause an error...

brakkar left a reply on Old Values Not Displaying

Here are all the current routes:

Route::get( '/', 'base\[email protected]' )->name('home');


#------------------------------------------------------------------------------------
# Users
#------------------------------------------------------------------------------------
Route::get('/user/login', 'users\[email protected]');

Route::get( '/user/register', 'users\[email protected]' );
Route::post( '/user/register', 'users\[email protected]' );

brakkar left a reply on Old Values Not Displaying

Sure thanks, here is the form

<form method="post" action="/user/register">
    {{csrf_field() }}
    username:<br>
    <input type="text" name="username" value="{{ old('username') }}"><br/>
    @if ($errors->first('username'))
        <li>
            {{ $errors->first('username')  }}
        </li>
    @endif
    <br><br>


    Email:<br>
    <input type="email" name="email" value="{{ old('email') }}"><br/>
    @if ($errors->first('email'))
        <li>
            {{ $errors->first('email')  }}
        </li>
    @endif
    <br><br>

    password:<br>
    <input type="password" name="password" value="{{ old('password') }}">
    @if ($errors->first('password'))
        <li>
            {{ $errors->first('password')  }}
        </li>
    @endif
    <br><br>
    <button type="submit"> SUBMIT FORM</button>
</form>

And here is the controller:

class UsersController extends Controller
{
    public function login()
    {
        return view( 'users.login' );
    }


    #------------------------------------------------------------------------------------
    # Registration
    #------------------------------------------------------------------------------------
    public function create()
    {
        return view( 'users.registration' );
    }


    public function store()
    {
        # Validate
        $this->validate(request(), [
            'username' => 'required|min:2',
            'email' => 'required|email',
            'password' => 'required',
        ]);

        # Create
        $user = User::create(request(['username', 'email', 'password']));

        # Authenticate
        //auth()->login($user);

        # redirect
        return redirect()->home();
    }

}

and the routes

Route::get( '/user/register', 'users\[email protected]' );
Route::post( '/user/register', 'users\[email protected]' );

brakkar left a reply on Old Values Not Displaying

Nothing : value="" for all fields.

Thanks for password tip, this is just for testing, i'm far, far from production.

brakkar started a new conversation Old Values Not Displaying

Hello, I have this code in a blade template:

Email:<br>
<input type="email" name="email" value="{{ old('email') }}"><br/>
@if ($errors->first('email'))
    <li>
        {{ $errors->first('email')  }}
    </li>
@endif

error display works fine, but not the 'old' things.

The controler is very simple, do I need to do something special to enable old values:

public function store() { # Validate $this->validate(request(), [ 'username' => 'required|min:2', 'email' => 'required|email', 'password' => 'required', ]);

    # Create
    $user = User::create(request(['username', 'email', 'password']));

    # Authenticate
    //auth()->login($user);

    # redirect
    return redirect()->home();
}

brakkar started a new conversation Mandatory Migrations ?

Hello, I come from a framework where migrations are mandatory: lots of system parts depend on it.

What about laravel ? What if I build and update my database schema totally independently, from a gui tool like sequel pro, will this be an issue further down the road ?

31 Jan
2 years ago

brakkar left a reply on It Just.... Doesn't Work (valet)

Thanks for the link, I tried some of the solutions there, but it still didn't solve the problem and it didn't generated the sock file. Do you remember what you did exactly ?

brakkar started a new conversation It Just.... Doesn't Work (valet)

Hello, I followed the instructions on the laravel installation page to get local dev env working and got all sort of problems. I got to the point I have valet installed. Parked the parent dir of all my project.

When going to project.dev I get 502 Bad Gateway error. Looking at the log, I have a message like so:

2017/01/31 17:52:42 [crit] 12483#0: *13 connect() to unix:/Users/ME/.valet/valet.sock failed (2: No such file or directory) while connecting to upstream, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/Users/ME/.valet/valet.sock:", host: "rib.dev"

and it seems it doesn't find a valet.sock file which indeed doesn't exist. What am I supposed to do ?

I hope this all gets better.