sger

sger

Member Since 4 Years Ago

Experience Points 18,755
Experience Level 4

1,245 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 327
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.

20 May
3 years ago

sger started a new conversation One To One Relationship Returns String Instead Of Carbon

I have One to one relationship my model contains datetime column type for example:

$myModel = \App\MyModel; $myModel->mydate = \Carbon\Carbon::create(2016, 06, 18, 24);

var_dump($myModel->mydate);

in this case returns carbon object but with

$user = \App\User; $user->model()->save($myModel);

var_dump($user ->model->mediate);

in this case returns string

any ideas?

12 Apr
3 years ago

sger left a reply on Override PostRegister

i think the solution is to override

public function register(\Request $request) { dd($request); }

sger started a new conversation Override PostRegister

Hello,

i'm trying to override postRegister to prevent autologin so in AuthController i have

protected function create(array $data) {} public function postRegister(Request $request) { return redirect('/'); }

but i'm getting Argument 1 passed to Illuminate\Auth\SessionGuard::login()

any ideas?

29 Mar
3 years ago

sger started a new conversation Default Auth Templates Validation Is Not Working

Hello,

Just created a new project with the default auth templates but login, register validation is not working any ideas?

sger left a reply on Postgres Database Connection With Homestead

fixed the correct port is 5432 and not 54320

sger started a new conversation Postgres Database Connection With Homestead

Hello,

i'm using homestead but i cant connect to database from laravel project this is my .env file

DB_CONNECTION=pgsql DB_HOST=localhost DB_PORT=54320 DB_DATABASE=homestead DB_USERNAME=homestead DB_PASSWORD=secret

from postico i can connect with db

any ideas?

10 Oct
3 years ago

sger left a reply on CSRF With API

Thanks guys i'm using an API token.

sger started a new conversation CSRF With API

Hello,

I'm doing a iOS app and i created an API with laravel its important to send csrf through every post, put, delete?

Any ideas how to send this value from client (maybe as a header)

23 Sep
3 years ago
29 Jul
3 years ago

sger left a reply on SQLSTATE[23000]: Integrity Constraint Violation:

my solution is to re-create the migration with nullable values

sger left a reply on SQLSTATE[23000]: Integrity Constraint Violation:

basically in the creation of the model i want to add only the first foreign key (project_id) not the second (item_id) is this possible?

sger left a reply on SQLSTATE[23000]: Integrity Constraint Violation:

yes thats correct it doesn't exist but i'm trying to do something like this

\DB::statement("SET foreign_key_checks=0"); $asset->item_id = null; \DB::statement("SET foreign_key_checks=1");

but also fails any ideas how to create a model with null foreign key?

sger started a new conversation SQLSTATE[23000]: Integrity Constraint Violation:

Hello,

I have one model which contains 2 foreign keys:

$table->integer('project_id')->unsigned();
$table->foreign('project_id')->references('id')->on('projects')->onDelete('cascade');
$table->integer('item_id')->unsigned();
$table->foreign('item_id')->references('id')->on('items')->onDelete('cascade');

Every time i creating this model i'm getting the following message:

SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`db`.`mytable`, CONSTRAINT `db_item_id_foreign` FOREIGN KEY (`item_id`) REFERENCES `publications` (`id`) ON DELETE CASCADE) 

it works ok for the first foreign key but not for second

Any ideas?

23 Jul
3 years ago

sger left a reply on Remove Relationship One To Many

its not working actually delete all childs what happened to detach any ideas?

sger left a reply on Remove Relationship One To Many

the correct syntax is

$parent->childs()->delete(\Input::get('id'));

sger started a new conversation Remove Relationship One To Many

Hello,

I have one to many relationship and i want to detach it with the following code

$child = \App\Asset::find(\Input::get('id'));

$parent = \App\Parent::find(\Input::get('parent_id')); $parent->childs()->detach(\Input::get('id')); $parent->save();

but i'm getting this

Call to undefined method Illuminate\Database\Query\Builder::detach()

sger left a reply on Form With Name Route Problem

Solve it with by declaring

Route::controller('item', 'ItemsController');

and creating remove method in ItemsController.

sger started a new conversation Form With Name Route Problem

Hello, I have this route: Route::post('item/remove', ['as' => 'remove', 'uses' => 'ItemController@remove']);

and I'm using a form like this:

{!! Form::open(array('route' => 'remove'')) !!}

but it redirects me back to

domain.com/item/remove with 404 message

any ideas?

21 Jul
4 years ago

sger left a reply on Array To Object

heres my method:

$news = \App\Post::all();
$videos = \App\Video::all();

$merged_items = array_merge_recursive($projects->toArray(), $news->toArray());
    $merged_items = array_reverse(array_sort($merged_items, function ($value) {
      return $value['created_at'];
    }));

return view('views.items')
    ->with('items', $merged_items);

then in my blade i'm using a @foreach ($items as $item) but can't access for example with $item->id

sger started a new conversation Array To Object

Hello,

Best way to convert array to object blade views can't handle arrays i'm getting this exception

Trying to get property of non-object

Any ideas?

sger left a reply on Merge And Sort Array Collection

another question is possible to merge 3 arrays?

sger left a reply on Merge And Sort Array Collection

solve it with the following code:

$projects = \App\Project::all();
    $news = \App\Post::all();
    $all = $projects->merge($news);

    //ASC
    $all = array_values(array_sort($all, function ($value) {
      return $value['created_at'];
    }));

    //DESC
    $all = array_reverse(array_sort($all, function ($value) {
      return $value['created_at'];
    }));

i posted 2 ways for ASC, DESC

sger started a new conversation Merge And Sort Array Collection

Hello,

I have 2 collections and i want to merged them with the following code

$projects = \App\Project::all();
$news = \App\Post::all();
$all = $projects->merge($news);

and then i want to sort with ASC order using create_at with:

$all->sortBy(function($item)
 {
      return $item->created_at;
 });

but its not working always getting wrong results any ideas?

19 Jul
4 years ago

sger started a new conversation Input::get("array") With Form Request

Hello,

I have a form which contains a list like the following:

{!! Form::open(array('url'=>"items/create')) !!}
      <div class="form-group">
        {!! Form::label('name') !!}
        {!! Form::text('name', '', array('class' => 'form-control')) !!}
      </div>
      <div class="form-group">
        {!! Form::label('item_id', 'Select Item') !!}
        {!! Form::select('item_id', (['0' => 'Item'] + $items), null, array('class' => 'form-control', 'id' => 'test')) !!}
      </div>
       <div id="items">
        <ul></ul>
      </div> 
      {!! Form::submit('Submit', array('class' => 'btn btn-default')) !!}
      {!! Form::close() !!}
}

every time i select something from Form::select i'm doing an append to

    now on post request i want to pass that info which is in form of

    • item1

    and retrieve the array like name for example

    Input::get("name") to get the name

    i want to do something similar with list items

    Any ideas?

    17 Jul
    4 years ago

    sger started a new conversation Routing Problem

    Hello,

    I have 2 routes

    Route::controller('test/news', 'NewsController'); Route::get('test/news/{id}/edit', 'NewsController@edit');

    and in my NewsController i have declared the method:

    public function edit($postId) { return $postId; }

    but when i'm hitting test/news/6/edit

    NotFoundHttpException in Controller.php line 269: Controller method not found.

    Any help?

    13 Jul
    4 years ago

    sger left a reply on White Screen

    i think the problem is with php version 5.4.41-0

    sger left a reply on White Screen

    is seems that nothing is executed at all the whole project is under /var/www

    sger left a reply on White Screen

    i try both but nothing any help on this issue?

    sger started a new conversation White Screen

    Recently install L5 in google cloud in a lamp stack uploaded everything trying to access site from IP/public but i'm getting white screen

    also Failed to load resource: the server responded with a status of 500 (Internal Server Error) IP/public/index.php

    sudo chmod 775 -R storage/

    didn't work

    any ideas?

    sger left a reply on Override AuthController

    this is not the problem all my routes have a prefix for lang for example en/about but when i'm submitting a form its not working.

    sger started a new conversation Override AuthController

    Is possible to override route /auth/login to login, register i want to prefix all my routes with lang, Any ideas?

    05 Jul
    4 years ago

    sger started a new conversation Post Request With Csrf

    I'm using L5 for rest api i want to use csrf with a post request like this for example:

    Route::post('register', 'UserController@register');

    but i'm getting this error TokenMismatchException in VerifyCsrfToken.php line 53: if i comment out line \App\Http\Middleware\VerifyCsrfToken::class, in Kernel.php it works any idea how to do post api requests with csrf?

    03 Jul
    4 years ago

    sger left a reply on Sentinel And Laravel

    you are correct my mistake

    sger left a reply on Sentinel And Laravel

    its a post request

    Route::post('register', function () { $credentials = [ 'email' => 'john.doe@example.com', 'password' => 'password', ];

    $user = Sentinel::register($credentials);

    });

    sger started a new conversation Sentinel And Laravel

    Hello i'm using sentinel and this is my route:

    Route::post('register', function () { $credentials = [ 'email' => 'john.doe@example.com', 'password' => 'password', ];

    $user = Sentinel::register($credentials);

    });

    but i'm getting this error

    MethodNotAllowedHttpException in RouteCollection.php line 201

    any ideas?

    06 Oct
    4 years ago

    sger left a reply on Count Relationships

    Thanks

    sger left a reply on Count Relationships

    this is my solution

    public function getTotalAttribute() { return $this->files()->count(); }

    public function toArray()
    {
        $array = parent::toArray();
        $array['total'] = $this->total;
        return $array;
    }
    

    sger left a reply on Count Relationships

    i'm going to override toArray() is this is for performance reasons?

    sger left a reply on Count Relationships

    yes this is correct guys thanks

    but

    public function projects() { return $this->hasMany('Project'); }

    returns an array from all rows how to add $project->files()->count(); into this array?

    sger started a new conversation Count Relationships

    Hello,

    I have 3 models User, Project, Files i want to count the number of files per project

    heres my relationship

    public function files() { return $this->hasMany('File'); }

    inside project model also user has many projects

    I'm still learning

    Thanks!

    23 Sep
    4 years ago

    sger started a new conversation Best Way To Update Foreign Key

    Hello,

    Simple question i'm new to laravel.I have this migration file

    Schema::create('lists', function(Blueprint $table) { $table->increments('id'); $table->string('title', 255); $table->integer('user_id')->unsigned(); $table->foreign('user_id')->references('id')->on('users'); $table->timestamps(); });

    and i want to update $table->foreign('user_id')->references('id')->on('users'); with ->onDelete('cascade');

    Best way to do this?

    Thanks

    17 Sep
    4 years ago

    sger left a reply on Query Builder

    solution

    $results = Link::where(DB::raw('DATE(NOW()) - DATE(created_at)'), '<', DB::raw('1 AND reset_code = ?'))->setBindings([$code]) ->get();

    with setBindings

    sger started a new conversation Query Builder

    Hello,

    Newbie question i'm trying to convert the following sql query

    SELECT * FROM links WHERE (DATE(NOW()) - DATE(created_at)) < 1 AND code = '10'

    with the following

    $results = Link::where(DB::raw('DATE(NOW()) - DATE(created_at)'), '<', DB::raw('1 AND code = :code'), array('code' => $code))->first();

    but i'm getting Array to string conversion error

    Any ideas?

    Thanks!!!

    16 Sep
    4 years ago

    sger left a reply on Eloquent Returns Int As String

    so this is normal ? thanks man

    sger started a new conversation Eloquent Returns Int As String

    Hello,

    I'm using a relationship with hasMany when i'm getting $user->photos eloquent returns id as string any idea?

    13 Sep
    4 years ago

    sger left a reply on Namespace

    Thanks

    i've added

    use Illuminate\Support\Facades\Mail;

    which is the same thing i quess

    Thanks again

    sger started a new conversation Namespace

    Hello,

    I'm very new to laravel and php my simple question is i created a class EventsHandler which lives under api\handlers\EventHandler within this class i want to access Mail::send method any help how to do this?

    Thanks