Cyber Monday! Get 25% off for as long as you keep your subscription. New subscribers only.

Tikay

Tikay

Member Since 1 Month Ago

Experience Points
570
Total
Experience

4,430 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
1
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
570 XP
Nov
21
1 week ago
Activity icon

Replied to A Neat Way To Get All Sub Relation Results

Damn that package looks exactly what I was looking for, and more!

Thanks a lot :)

Activity icon

Started a new Conversation A Neat Way To Get All Sub Relation Results

Been getting used to using relationships between the same model.

Pages database table: pages

Columns: id, parent_id, ... (bunch of relationship unrelated ones)

class Page extends Model {

...(bunch of functions etc here)...

    public function parent() {
      return $this->belongsTo(Page::class, 'parent_id');
    }

    public function children() {
      return $this->hasMany(Page::class, 'parent_id')->orderBy('title');
    }

}

This works perfectly for direct children.

$children = $page->children;
$children_ids = $page->children->pluck('id')->toArray();

$parent = $page->parent;
$parent_id= $page->parent->id;

When asking for parent it returns the page where the id = current page's parent_id.

When asking for children it returns the pages where the parent_id = current page's id.

So all is well there.

Currently, in cases where I need siblings, I get the parent, and get the children thereof. Short enough.

But in cases where I'd want all descendants id's (children, children's children, etc) it gets ugly as I couldn't find a way to do it relationship wise.

$desc_ids = array();
foreach($page->children as $a) {
	array_push($desc_ids, $a->id);
 	foreach($a->children as $b) {
		array_push($desc_ids, $b->id);
		foreach($b->children as $c) {
			array_push($desc_ids, $c->id);
			foreach($c->children as $d) {
				array_push($desc_ids, $d->id);
				foreach($d->children as $e) {
					array_push($desc_ids, $e->id);
					foreach($e->children as $f) {
						array_push($desc_ids, $f->id);
					}
				}
			}
		}
	}
}

I've tried

public function descendants() {
	return $this->hasManyThrough(Page::class, 'parent_id');
}

and few other possible ways, but couldn't get it to work.

Would there be a way to get this relationship wise?

Nov
14
2 weeks ago
Activity icon

Replied to OrderBy Multiple Columns

Much appreciated, and thanks for the thorough explanation!

And will learn about both, but a step at a time :) I tend to learn easier with using examples, "pull them apart" and play around with them, is atleast how I've done it so far.

To be honest, most things I don't understand feel overwhelming, until I understand it more.

Again, thanks!

Activity icon

Replied to OrderBy Multiple Columns

Yeah my bad, didn't think about a parent_id having a parent_id and how they get sorted when I wrote my initial example.

Sadly query and relationship still blow my mind.

I'd gladly replace it with less complicated code, if it's not too much trouble I'd be greatly appreciated.

Nov
13
2 weeks ago
Activity icon

Replied to OrderBy Multiple Columns

Picked up Laravel a month ago, after 2 years of Wordpress usage, so yep, still a lot to learn ^^

You too!

Activity icon

Replied to OrderBy Multiple Columns

Amazing, thanks!

And yep, somewhat overwhelming, will have to up my knowledge on that.

Activity icon

Replied to OrderBy Multiple Columns

Hi,

I'm using mySQL.

Sadly can't say I know raw SQL, but seeing @michaloravec 's link, hope this is sufficient

CREATE TABLE models
	(`id` int, `parent_id` int, `title` varchar(1))
;
	
INSERT INTO models
	(`id`, `parent_id`, `title`)
VALUES
	(1, NULL, 'A'),
	(2, NULL, 'C'),
	(3, NULL, 'B'),
	(4, 3, 'F'),
	(5, 1, 'E'),
	(6, 3, 'D'),
	(7, 5, 'D'),
	(8, 5, 'C'),
	(9, NULL, 'C'),
	(10, 8, 'C'),
	(11, 9, 'B')
;

The result I'm looking for

(1, NULL, 'A')
- (5, 1, 'E')
- - (8, 5, 'C')
- - - (10, 8, 'C')
- - (7, 5, 'D')
(3, NULL, 'B')
- (6, 3, 'D')
- (4, 3, 'F')
(2, NULL, 'C')
(9, NULL, 'C')
- (11, 9, 'B')

Added the "-" to have it lined up to be have my example be clearer.

Having row's id be followed by those that have it as parent_id. Having those follow a general alphabetical order on title, like (2, NULL, 'C') being under (3, NULL, 'B') and those following it through parent_id in above example).

Activity icon

Replied to OrderBy Multiple Columns

Thanks for the quick on point response!

And I should have given a more in-depth example. if there would also be a (7, 5, 'D') (8, 5, 'C'), having a parent that has a parent, they do not follow.

http://www.sqlfiddle.com/#!9/5520a8/1

Edit: If I do ​ orderByRaw('coalesce(id, parent_id), parent_id is not null, title')->paginate($items); ​ They are listed just beneath the id, just not in alphabetical order.

Activity icon

Started a new Conversation OrderBy Multiple Columns

I've got a database table, with a bunch of columns, the ones I'm trying to order by are 'id', 'parent_id' and 'title'.

Thing is, I want the result to be something like:

title:A | id:1 | parent_id:null

title:E| id:5 | parent_id:1 <= here because parent_id = id from previous

title:B | id:2 | parent_id:null

title:C | id:3 | parent_id:null

title:D | id:6 | parent_id:3 <= here because parent_id = id from previous, but above id:4 due to title alphabetically

title:F | id:4 | parent_id:3 <= here because parent_id = id from previous, but under id:6 due to title alphabetically

A simple ​ return Model::orderBy('parent_id', 'asc')->orderBy('id', 'asc')->orderBy('title', 'asc')->paginate(10); ​ obviously doesn't do the trick.

Been search around, sadly can't find a solution or documentation.

Any push in the right direction is much appreciated.

Oct
15
1 month ago
Activity icon

Replied to 404 On Form Post With Laravel Collective

@sergiu17 Was a solution I tried earlier. But another one, sort of related to that, made it work!

Route::post('contact/submit', 'App\Http\Controllers\[email protected]');

Probably fixed with the use of "php artisan route:clear" you mentioned earlier.

I can fetch some sleep before it turns 7 AM now. Thanks alot! You all are a godsend with the rate of response!

Activity icon

Replied to 404 On Form Post With Laravel Collective

That actually fixed the other routes. Thanks!

If I click submit, I'm getting

Illuminate\Contracts\Container\BindingResolutionException
Target class [MessagesController] does not exist.

127.0.0.1 - - [15/Oct/2020:06:24:30 +0200] "POST /contact/submit HTTP/1.1" 500 572177 "http://basicwebsite.tikay/contact" "..."

Activity icon

Replied to 404 On Form Post With Laravel Collective

And just noticed that none of my routes do anything, if I comment them all out it doesn't change anything to any page...

Activity icon

Replied to 404 On Form Post With Laravel Collective

Didn't notice the typo when rewriting that line, thanks for noticing, though wasn't the cause. I've reformatted the 'contact/submit' in both route and form a few times, with and without "/" with no success.

Oct
14
1 month ago
Activity icon

Replied to 404 On Form Post With Laravel Collective

Sadly still leads to a 404 status.

Activity icon

Started a new Conversation 404 On Form Post With Laravel Collective

After making a few sites with wordpress, I thought it was time to learn and get used to Laravel. While quite educational content around, I've been struggling to find a solution to this issue. Form shows up nicely, but I get 404 page when I click submit and get sent to "contact/submit" After quite a few hours of failing to find a solution I come here, fingers crossed.

Form is on page "contact"

resources > views > contact.blade.php

{{Form::open(['url' => 'contact/submit'])}}
    <div class="form-group">
      {{Form::label('name', 'Name')}}
      {{Form::text('name', '', ['class' => 'form-control', 'placeholder' => 'Enter name'])}}
    </div>
    <div class="form-group">
      {{Form::label('email', 'E-Mail Address')}}
      {{Form::text('email', '', ['class' => 'form-control', 'placeholder' => 'Enter email'])}}
    </div>
    <div class="form-group">
      {{Form::label('message', 'Message')}}
      {{Form::textarea('message', '', ['class' => 'form-control', 'placeholder' => 'Enter message'])}}
    </div>
    <div>
      {{Form::submit('submit', ['class' => 'btn btn-primary'])}}
    </div>
{{Form::close()}}

routes > web.php

Route::get('contact', function () {
    return view('contact');
});

Route::post('/contact/submit', '[email protected]');

app > Http > Controllers > MessagesController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class MessagesController extends Controller
{
    public function submit(Request $request){
      $this->validate($request, [
        'name' => 'required',
        'email' => 'required'
      ]);

      return 'SUCCESS';
    }
}

I have a feeling the routing is causing it, but then again, I'm new to this so probably not an educated assumption.

Thanks for any input.