janmoes

janmoes

Member Since 1 Year Ago

Experience Points
3,100
Total
Experience

1,900 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
19
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]racasts.com 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,100 XP
Sep
13
1 month ago
Activity icon

Replied to Validating Combination Of Two Fields

@bobbybouwmann sorry my bad. Your solution works. I kept testing on adding post_translations on the post with id 1 while i already had a post_translation on there for every available language haha. So i create a second post, tried to add a dutch translation to it twice, and by the second time i got the error that the language was already in use. So it works! :)

Activity icon

Replied to Validating Combination Of Two Fields

I tried your way, i even sent $post_id as the value of a hidden input, but i still get The lang id has already been taken.

Sep
12
1 month ago
Activity icon

Replied to Validating Combination Of Two Fields

i couldn't get it to work to get the data from the form within the validation rule. Basically what i try to accomplish is that every post_translation which is connected to a post, is only translatable once in every language for example post_translation with post_id 1 can only be translated in dutch once.

Activity icon

Started a new Conversation Validating Combination Of Two Fields

Hi there,

I'm having trouble with validation. I want a post_translation to have a unique combination of a post_id and lang_id. I've tried some stuff from the docs but didn't get it to work.

If a translation already uses a language or not, it keeps giving the error message "Lang id already in use". I've made the validation in a custom form request:

public function rules (Request $request) 
    {
        return [
            'lang_id' => ['required', Rule::unique('post_translations')->where(function ($query) {
                return $query->where('post_id', 1);
            })],
            'title' => 'required',
            'content' => 'required',
        ];
    }
Sep
08
1 month ago
Activity icon

Replied to Laravel 8: Jetstream; Livewire; Inertia Error

I also had that problem, making a new test project now. What is the preffered choice Inertiajs or livewire?

Jul
20
3 months ago
Activity icon

Replied to Composite Key Form Validation

got it working, appearently the `$table->unique(['post_id', 'lang_id']); needed to be underneath the timestamps line. Now i'm getting this sql error after i try to add a translation to the post with a language which i've already used on that post:

SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '1-1' for key 'post_translations_post_id_lang_id_unique' (SQL: insert into `post_translations` (`lang_id`, `title`, `content`, `post_id`, `updated_at`, `created_at`) values (1, nl2, nl2, 1, 2020-07-20 23:19:05, 2020-07-20 23:19:05))

Is there a way to turn that into a readable error message that i can return to the form when those values already exist?

Activity icon

Replied to Composite Key Form Validation

@michaloravec I've also added that line in my code, so that people can see what i've tried.

Activity icon

Replied to Composite Key Form Validation

@michaloravec yeah also tried it with ->primary, but both give me errors.

Activity icon

Started a new Conversation Composite Key Form Validation

I have a posts which have a one to many relationship with translations.

What i want to accomplish is that whenever you make a post, that i can only have 1 translation per available language. So a translation can only have once post_id = 1 and lang_id = 1. I've already tried adding ->unique and ->primary to the migration but i keep getting errors of multiple indexes etc. This is the migration:

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreatePostTranslationsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('post_translations', function (Blueprint $table) {
            $table->id();
            $table->integer('post_id')->index('post_id')->unsigned();
            $table->foreign('post_id')->references('id')->on('posts');
            $table->integer('lang_id')->index('lang_id')->unsigned();
            $table->foreign('lang_id')->references('id')->on('languages');
            //$table->unique(['post_id', 'lang_id']);
            $table->string('title');
            $table->string('content');
            $table->timestamps();
        });
    }

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

Jul
18
3 months ago
Activity icon

Replied to Preventing A Post From Being Created In Case A Validation Fails

Oh okay, well I think I will put all the validation code in a custom form request, so that I keep my controllers a little bit cleaner haha

Activity icon

Replied to Preventing A Post From Being Created In Case A Validation Fails

@artcore what is the difference between your 2 examples of validation?

Jul
17
3 months ago
Activity icon

Replied to Preventing A Post From Being Created In Case A Validation Fails

i've done it like that before, but even when the Translation validation fails, it still creates a Post tho.

Activity icon

Replied to Preventing A Post From Being Created In Case A Validation Fails

i just heard that if you have a custom form request for example storeTranslation. The whole store() method in my controller wont be executed when the validation fails, which is what i need! :)

Activity icon

Replied to Preventing A Post From Being Created In Case A Validation Fails

the validated data function looks like this:

protected function validatedData(){
        return request()->validate([
            'lang_id' => 'required',
            'title' => 'required',
            'content' => 'required',
        ]);
    }
Activity icon

Started a new Conversation Preventing A Post From Being Created In Case A Validation Fails

Hey there,

I have a post controller which i use to create posts and it's oneToMany relations translations. A post only has an id and timestamps, while translation include all the content for the post. Because of the fact that posts don't have form fields, i can't validate them, so when a validation normally would fail, it would still create a post. A post/translation creation for me looks like this:

public function store(Request $request)
    {
        if($this->validatedData()){
            $post = Post::create();
            $post->translations()->create($this->validatedData());

            return redirect('/posts');
        }   
    }

Any idea of how to fix that? My way looks kinda ugly, and i was wondering if a custom formrequest could be handy.

Jul
08
3 months ago
Activity icon

Replied to Receiving Specific Child From Parent

Note i can create connected translations to a post using this kind of code:

$post = Post::create();

$post->translations()->create($this->validatedData());

Maybe i could use something similair like

$translation = $post->translations()->where(['lang_id', '=', 'EN'])->get();

?

Activity icon

Started a new Conversation Receiving Specific Child From Parent

I have a relationship where posts can have multiple translations. In the admin panel i can easily do

@foreach($post->translations as $translation)

to get the right translations that are connected with a specific post_id.

In the show() function from the post controller, i want to show the translation from a spefific post, depending on the locale that is active at the moment. I've already tried stuff similair to this:

public function show(Post $post)
    {
        $translation = PostTranslation::find()->where(["post_id", "=", $post->id], ["lang_id", "=", 1])->get();
        return view('posts.show', compact('translation'));
    }

Also i'm not sure how to get the current locale code within the controller, i'm using: https://github.com/mcamara/laravel-localization But haven't had success with it yet.

Jul
07
3 months ago
Activity icon

Replied to Saving OneToMany Relationship To Database

Interestingly i found this while reading $table->unique('post_id', 'lang_id'); this will probably make sure that every post only has one translation per available language?

Activity icon

Replied to Saving OneToMany Relationship To Database

It works now. What is the ->index() part actually for with that foreign key stuff?

Activity icon

Replied to Saving OneToMany Relationship To Database

I changed this $table->integer('post_id')->index('post_id')->unsigned(); into $table->integer('post_id')->unsigned(); now everything works again :)

Activity icon

Replied to Saving OneToMany Relationship To Database

I wanted to test the system, by refreshing the migrations and seeding the database again, then i got this error:

 SQLSTATE[42000]: Syntax error or access violation: 1072 Key column 'post_id' doesn't exist in table (SQL: alter table `post_translations` add constraint `post_translations_post_id_foreign` foreign key (`post_id`) references `posts` (`id`))

I googled it and it said:

ou should create column before creating a foreign key:

$table->integer('category_id')->unsigned();
$table->foreign('category_id')->references('id')->on('categories');

But you told me to remove that kind of line

Activity icon

Replied to Saving OneToMany Relationship To Database

I aslo need to add some sort of delete option, that whenever you delete a whole post, that it also removes all translations, and some sort of composite key that every post can only have 1 translation per language which is available

Activity icon

Replied to Saving OneToMany Relationship To Database

yeah well, in the admin panel you will see every translation per post, so i could just use that id to create an update link or so.

Activity icon

Replied to Saving OneToMany Relationship To Database

@michaloravec Hey it worked, thanks! Updating will just be the same right but than i gotta do $post = Post::find($id); to get the right post and translations connected to it?

Activity icon

Replied to Saving OneToMany Relationship To Database

and the $post->translations()->create($this->validatedData()); is in the controller right?

Activity icon

Replied to Saving OneToMany Relationship To Database

@michaloravec post_id will probably only be set in the post_translations table if you use the post::find instead of post::create?

Activity icon

Replied to Saving OneToMany Relationship To Database

That would probably still give that error right? I thought it automatically adds a post_id to translations because i made it a foreign_key in the migration:

 Schema::create('post_translations', function (Blueprint $table) {
            $table->id();
            $table->integer('post_id')->index('post_id')->unsigned();
            $table->foreign('post_id')->references('id')->on('posts');
            $table->integer('lang_id')->index('lang_id')->unsigned();
            $table->foreign('lang_id')->references('id')->on('languages');
            $table->string('title');
            $table->string('content');
            $table->timestamps();
        });
Activity icon

Replied to Saving OneToMany Relationship To Database

@tykus I tried this:

public function store(Request $request)
    {
        $post = Post::create();
        
        // dd($post->id);
        $translation = PostTranslation::create($this->validatedData());

        $post->translations()->save($translation);
        // $post->save();

        // $post->translations()->save($validatedData);

        // $translation = new PostTranslation();
        // $translation->post_id = $post->id;
        // $translation->lang_id = $request->lang_id;
        // $translation->title = $request->name;
        // $translation->content = $request->text;
        // $translation->save();

        return redirect('/posts');
    }

protected function validatedData(){
        return request()->validate([
            'lang_id' => 'required',
            'title' => 'required',
            'content' => 'required',
        ]);
    }

When i fill in the form to create a post with a translation, this is the error i'm getting:

SQLSTATE[HY000]: General error: 1364 Field 'post_id' doesn't have a default value (SQL: insert into `post_translations` (`lang_id`, `title`, `content`, `updated_at`, `created_at`) values (1, jan, jan, 2020-07-07 19:04:30, 2020-07-07 19:04:30))
Activity icon

Started a new Conversation Saving OneToMany Relationship To Database

Is it possible if you have a Post with multiple translations (relationship is the post_id), That whenever you create a post you can directly save a translation connected to it like this?

$post = new Post();
$post->translations()->save($data);

post wouldn't need any data, the only fields are an id and timestamps, it just exists to save multiple translations of a post connected to eachother.

Jul
01
3 months ago
Activity icon

Replied to Localize Data In Database

Another problem with it, you can add 2 items at the same time to the database, but editing it at the same time might be hard

Activity icon

Started a new Conversation Localize Data In Database

Hey there, i'm using https://github.com/mcamara/laravel-localization to translate urls, and the standard Laravel localization stuff to have a translated website. Although i will have posts on my website that are in 2 maybe 3 languages. I want to have one html form in the admin panel, to save the post in all 2/3 languages, and that every post (language based) gets his own row in the posts table. I was thinking of giving it a post_id and language code, so that everytime you save a post. All same posts but different languages have the same post_id, but a different language code, so that i can select a specifc post and use the $locale parameter to get that specific post in the right language.

This is what i have so far:

public function store(Request $request){
    $post = new Post();
    $post->lang = 'NL';
    $post->name = $request->name_nl;
    $post->text = $request->text_nl;
    $post->save();
 
    $post = new Post();
    $post->lang = 'EN';
    $post->name = $request->name_en;
    $post->text = $request->text_en;
    $post->save();
}

any ideas?

Jun
30
4 months ago
Activity icon

Replied to Laravel Localization

@walidabou Do you also know how to loop the routes in the html, still connecting to the same language, so that when dutch is active, only dutch links will appear in the nav and so on?

Activity icon

Replied to Laravel Localization

Got everything working with your prefered package!

Activity icon

Replied to Laravel Localization

Uhm i read the docs, isn't it just possible to declare a route in a translator file like about => 'over ons' and use the translation function within the routes file like Route::get(__trans('routes.about')) ?

Jun
29
4 months ago
Activity icon

Replied to Laravel Localization

I'll take a look at that when i'm home, thanks!

Activity icon

Started a new Conversation Laravel Localization

Hey there, i just started using Laravel's localisation, built in stuff. It's pretty easy to use, you give any url a parameter and from that it decides which language it needs to grab from the file with content. But i was wondering. If i have a dutch url, for example: '/over-ons' in english that's /about-us, is it even possible to translate the url aswell?

Jun
09
4 months ago
Activity icon

Replied to Laravel Auth Without Registration

Cool, it is something that i need to use in a couple of days. If i still have questions then i'll ask them here!

Thanks everyone!

Activity icon

Replied to Laravel Auth Without Registration

Oh okay, i never knew that it was possible to make your own artisan commands, so you type in the first command, and the fields values will be asked, and you can fill them in then, i don't need custom fields if i just use laravel's basic user fields right?

Activity icon

Replied to Laravel Auth Without Registration

I read the package docs, only can't find a whole cmd line how to create a user, maybe not looking good?

Or do i just run the command php artisan make:user and it will automatically ask questions, what's the username, what's the password etc?

Activity icon

Replied to Laravel Auth Without Registration

I'll try that, and maybe that package you send, saves me probably from writing multiple lines with tinker i guess

Activity icon

Replied to Laravel Auth Without Registration

So everything you write in cmd using tinker, won't be saved in a file or so?

Activity icon

Started a new Conversation Laravel Auth Without Registration

Hello everyone,

I want to make a Laravel application.

It is just a simple portfolio website, where there's only one user that is allowed to login and modify content (the owner of the site). I know that i can include Laravel Auth to the project and disable registering by doing:

Auth::routes(['register' => false]);

So i can just make the one and only admin account by creating it with the user class in cmd by using php tinker, or just placing the user in a seeder, but won't both solutions cause safety issues, that people can try and find the user data somewhere?