Eluknow

Eluknow

Member Since 3 Years Ago

Student at INSA Centre-Val de Loire

Experience Points 1,520
Experience Level 1

3,480 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 0
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.

29 Dec
6 months ago

Eluknow left a reply on Should I Use Laravel For A Static Part Of My Website ?

Thanks for your answer, you convinced me ! I going to use Laravel for both side of my website. (I didn't know that view routes were as fast as possible, thank you for giving me this information).

Eluknow started a new conversation Should I Use Laravel For A Static Part Of My Website ?

Hi, I have a website that can be divided in two parts :

  • first, a part presenting the society, their products with a contact form etc.
  • second, a restricted back office for the team, to handle customers and the team.

In one hand, I had thought to develop the first part without Laravel and only the second part with it, because I believed Laravel was too complex for some static pages without any db interactions so, for me, it would slow down the website. But, now, as I use it for the back office and as the static pages must be translated in a couple of languages, I wonder if I'm still right not to use Laravel for the static part of the website. Would Laravel really slow down the website (compared to the same website with only basic MVC using PHP) ? Is it better to use Laravel for both static front office and dynamic back office ?

Thanks for reading,

28 Dec
6 months ago

Eluknow left a reply on API With Laravel And Different Types Of Datas

Thanks a lot guys, I now see I had some misunderstandings.

Actually I now know how to store my datas, and I also learnt more about Laravel Telescope. Plus, i watched more about Reinink. This was very helpful.

Just a last question, linked with all we said before : in order to store my datas in DB, which DBMS (hope it's the good translation for SGBD in French) do you advice me to use ? A basic mysql (MariaDB) is good, or rather a nosql like MongoDB ?

26 Dec
6 months ago

Eluknow left a reply on API With Laravel And Different Types Of Datas

Thanks for your answer.

If i use "LineModel->morphsTo->...", it means that i have to create a table for each LineContent & LineMedia, didn't it ? I really believe it's not a good idea to multiply the number of tables (and so, the number of sql requests) in my case.

In fact, i will have a huge app with a lot of models including users, users_preferences, societies, estimates, bills, newsletters... Each user will be able to generate estimates, bills or newsletters. He will have a design and he will be able to modify contents, color, type of contents... And finally you receive json arrays presented above (it's the result of a generated newsletter).

I hope it will help.

Eluknow started a new conversation API With Laravel And Different Types Of Datas

Hi, I'm working on a project's brief and I see I need different kind of datas. For instance, i need common datas such as users, messages... But i also manipulate datas that looks like that :

{
    "name":"name",
    "lines":[
        {"order":0,"type":"line-content","bgcolor":"rgb(247,247,247)","content":"<b>Contactez-nous<\/b> pour organiser vos \u00e9v\u00e8nements les plus fous !"},
        {"order":1,"type":"line-media","bgcolor":"rgb(255,0,55)","content":"Et une ligne en plus ! Cliquez pour modifier","title":"Titre (clic pour modifier)","position":2,"imageSrc":".\/images\/defaultright.png","link":".\/images\/defaultright.png","plus":"test.html"}
    ],
    "address":"6 Boulevard du G\u00e9n\u00e9ral Leclerc<br\/>B\u00e2timent C - 92110 Clichy","logo":".\/images\/Logo.png"
}```
You see, I manipulate json arrays with sub-arrays (in the example above, "lines" is a sub-array). I will develop an API to work, but i don't manage to know how i can store these datas. 
Because I can't store "lines" in a table's column, but also, i don't need to create another table for "lines" because they only own to one json array ; it would create many requests for something useless. 

Therefore, I had thought about doing a common database and storing these type of json arrays in files .json. But my question is, if I do that, first : is it well ? second : how will I switch between storage in db and storage in files in my models ? 

Thanks a lot for reading, hope it was understandable
09 Nov
8 months ago

Eluknow left a reply on Copy Html Code Of A Component

Thanks for you help @d9705996. Nevertheless, this code doesn't work : indeed, generatedContent doesn't contain '

Value of title

', you see what i mean ? And even i manage to put the div #app "innerHTML" into generatedContent, it will also contain ... and i just want "

Value of title

" in my case. i'm not sure to clearly explain my pb, i'm sorry :/

08 Nov
8 months ago

Eluknow started a new conversation Copy Html Code Of A Component

Hi everyone,

I try to create a "newsletter" generator with vueJS. To briefly explain how it works, let's look at an example with the newsletter's title : there is an automatic generated newsletter with a title, and when i click on the title, an input with v-model appears and i can update the title. ok, great, no problem to do that. The problem occurs when I want to retrieve the final code of the newsletter with all the updates that i did. I want to retrieve the code in a textarea.

Here is a simple example to show what i want with only vueJS and more complex code :

<!DOCTYPE html>
<html lang="fr">
<head>
    <meta charset="utf-8">
</head>
<body>
    <div id="app">
        <h1>{{ title }}</h1>
        {{ generatedContent }}
        <input v-model="title" />
    </div>

    <button id="clic"></button>

    <textarea id="generatedContent">
    </textarea>
    
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <script src="main.js"></script>

    <script>
    var generatedContent = document.getElementById("generatedContent");
    document.getElementById("clic").addEventListener('click', function(){
        generatedContent.value=document.getElementById("app").innerHTML;
    })
    </script>
</body>
</html>```

```javascript
let app = new Vue({
    el: '#app',
    data:{
        title:"Mon titre"
    },
})```

Is someone able to explain me how to do that with vueJS only ? 
Thanks a lot for reading me, 
Have a nice day !
14 Jul
1 year ago

Eluknow started a new conversation V-model On Textarea In Component

Hi, I'm a new user of VueJS and I try it thought little projects, but, as you can imagine, I have some issues. In fact, I'm trying to transform a h2 into a textarea in order to update it dynamically. So, my html :

        <div class="table-responsive">
            <table class="table table-hover table-bordered">
                <thead class="thead-dark">
                    <tr>
                        <th scope="col">Nom de la prestation</th>
                        <th scope="col">Temps estimé</th>
                        <th scope="col">Taux</th>
                    </tr>
                </thead>
                <tbody>
                    <tr is="prestation" v-for="prestation in prestations" :title="prestation.title" :timework="prestation.timework" :taux="prestation.taux"></tr>
                </tbody>
            </table>
        </div>
    </div>```
And my main.js :
```javascript
Vue.component('prestation', {
    props : {
        title:String,
        timework:Number,
        taux:Number,
    },
    data () {
        return {
            titleIsUpdated: false
        }
    },
    template: `
        <tr>
            <td>
                <h2 class="title-modal" v-if="!titleIsUpdated" @click.prevent="updateTitle">{{ title }}</h2>
                <textarea v-if="titleIsUpdated" @keyup.enter="updateTitle" v-model="title">{{ title }}</textarea>
            </td>
            <td>
                <span class="time">{{ timework }}</span>
            </td>
            <td>
                <span class="taux">{{ taux }}</span>
            </td>
        </tr>`,
    methods: {
        updateTitle () {
            this.titleIsUpdated = !this.titleIsUpdated;
        }
    }
})

let vm = new Vue({
    el: '#app',
    data : {
        prestations : []
    },
    created () {
        this.prestations.push({title:"Prestation test", timework:5, taux:100})
    }
})```

As you can see I created both h2 and textarea tags that appear if titleIsUpdated is true/false, and I'm using v-model title to dynamically update h2. But, I obtain : '[Vue warn]: Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-renders. Instead, use a data or computed property based on the prop's value'. I have already read https://vuejs.org/v2/guide/components.html#Using-v-model-on-Components but I don't manage to use it in my situation... Can someone explain me ? 

Thanks a lot !
17 Jul
2 years ago

Eluknow started a new conversation Duplicate Queries

Hi ! In order to upgrade my code, i've updated an eloquent request from :

$quests = QuestsGroup::join('user_quest', 'quests_groups.id', '=', 'user_quest.quests_group_id')->where('user_quest.user_id', Auth::user()->id)->where('quests_groups.step', Auth::user()->informations->quests_step)
            ->join('quests', function($join) {
                $join->on('quests.quests_group_id', '=', 'quests_groups.id')->on('quests.level', '=', 'user_quest.level');
            })
            ->select('quests_groups.title', 'quests_groups.slug', 'quests.*')
            ->get();

To :

$quests = Quest::join('quests_groups', 'quests_groups.id', '=', 'quests.quests_group_id')->where('user_quest.user_id', Auth::user()->id)->where('quests_groups.step', session()->get('users_informations.quests_step'))
            ->join('user_quest', function($join) {
                $join->on('user_quest.quests_group_id', '=', 'quests_groups.id')->on('quests.level', '=', 'user_quest.level');
            })
            ->select('quests_groups.title', 'quests_groups.slug', 'quests.*')
            ->with(['answers' => function($query) {
                $query->where('user_id', Auth::user()->id);
            }])
            ->get();

But, when I use the following function with a quest returned by the request below, the sql query that attaches badge is duplicated 5 times.

protected function quest_gene_1($quest)
    {
        if(Topic::join('messages', 'topics.id', '=', 'messages.topic_id')->where('topics.author_id', Auth::user()->id)->where('topics.forum_parent', config('quests.id_forum_to_introduce_itself'))
            ->count() >= 1)
        {
            $badge = Badge::where('slug', 'apprenti_codeur')->first();
            Auth::user()->badges()->attach($badge->id);
            $this->passQuest($quest->quests_group_id, 2, $flash);
        }
    }

Whereas I use the first function (with QuestsGroup), there is no duplications... May someone help me ? Thanks

19 Jun
2 years ago

Eluknow started a new conversation Request SQL That Need Another Request

Hi ! I'd like to improve my following sql request :

$quests_groups = QuestsGroup::whereIn('id', User_Quest::where('user_id', Auth::user()->id)->pluck('quests_group_id'))->get();

As you can see, I wanna retrieve the quests' groups that has the IDs found in the pivot table "User_Quest".

Is it possible to use just one request instead of two ? Thanks

04 Mar
2 years ago

Eluknow left a reply on Dynamical Var In Master Layout

I checked and... you're right. The connection failed. But now it's solved ! Thanks a lot !

Eluknow left a reply on Dynamical Var In Master Layout

Okay, thanks ! I tried with event broadcasting with Pusher. But I've this error : [Log] Pusher : No callbacks on my-channel for pusher:subscription_succeeded (pusher.min.js, line 8) [Log] Pusher : Event sent : {"event":"pusher:ping","data":{}} (pusher.min.js, line 8) [Log] Pusher : Event recd : {"event":"pusher:pong","data":{}} (pusher.min.js, line 8)

By using this tutorial : https://blog.pusher.com/writing-realtime-apps-with-laravel-5-and-pusher/

Need help :( :p

Eluknow started a new conversation Dynamical Var In Master Layout

Hi ! I've to pass a var in a master layout. So, I use the AppServiceProvider like that :

public function boot()
    {
        view()->composer('layouts.fo', function($view)
        {
            $view->with('notifications', PrivateMessage::where('recipient_id', Auth::user()->id)->where('state', '<', 2)->count());
        });
    }

You will probably understand that it's a number of notifications. Nevertheless, I would like that this number updates even if the user don't reload the page. With setTimeOut() function (jQuery) for instance. But I don't know if it's possible, and if it is, how to do it. Is someone able to help me ? Thanks !

04 Feb
2 years ago

Eluknow started a new conversation Upgrade This Blade View ? (eloquent Request Used Several Times)

Hi ! I'm creating a little forum on my website. So I need to display on a same page all the topics and some informations about each topics (like their last post (called "message" here)). So, I've got this code :

<a href="{{ route('front.topics.create', ['id' => $forum->id]) }}">Créer un nouveau sujet</a>
        @if(count($forum->topics))
            @foreach($forum->topics as $topic)
                <article class="category-topic">
                    <header class="header">
                        <h2><a href="{{ route('front.topics.show', ['id' => $topic->id]) }}">{{ $topic->title }}</a></h2>
                        <div>
                            <div class="nb-reply">42 messages</div>
                        </div>
                        <p>
                            {{ str_limit($topic->messages()->orderBy('id', 'desc')->first()->content, 100) }}
                        </p>
                    </header>
                    <aside class="last-reply">
                        <p>
                            <a class='last-topic' href="{{ route('front.topics.showMessage', ['topic' => $topic->id, 'message' => $topic->messages()->orderBy('id', 'desc')->first()->id]) }}">{{ $topic->messages()->orderBy('id', 'desc')->first()->content }}</a> <br>
                            Il y a <time datetime="">{{ $topic->updated_at->diffForHumans() }}</time> <br>
                            Par <a class='author' href=''>{{ $topic->messages()->orderBy('id', 'desc')->first()->author()->username }}</a> <br>
                        </p>
                    </aside>
                </article>
            @endforeach
        @else
            Il n'y a pas encore de sujets dans ce forum. <a href="{{ route('front.topics.create', ['id' => $forum->id]) }}">Créer le premier</a>
        @endif 

I'm not sure this code is the best xD. The fact to use several times the code "$topic->messages()->orderBy('id', 'desc')->first()" disturbs me. I should put this code in a var for instance ? But how to do that with blade ? Thanks a lot !

15 Jan
2 years ago

Eluknow started a new conversation Function In Blade View

Hi ! I come here today because I've got a problem about using a function in blade view. I've got this code : '''php public function index() { $categories = Tutorialscategory::roots()->get();

    function renderNode($node) {
      echo "<li>";
      echo "<b>{$node->title}</b>";

      if ( $node->children()->count() > 0 ) {
        echo "<ul>";
        foreach($node->children as $child) renderNode($child);
        echo "</ul>";
      }

      echo "</li>";

    }
    echo "<ul>";
        foreach($categories as $category) renderNode($category);
    echo "</ul>";
    //return view('backoffice.tutorials.index');
}
As you can see, the function renderNode is used inside the function itself. So, if I want to display the tree in blade view, I really don't know how to do... In fact, I should use that inside blade view : 
```php
 echo "<ul>";
            foreach($categories as $category) renderNode($category);
        echo "</ul>";

Does someone know how to solve this problem ? Thanks a lot

14 Jan
2 years ago

Eluknow left a reply on How To Upgrade This Code ?

I found another way to do what I wanted to do, thanks !

Eluknow started a new conversation How To Upgrade This Code ?

Hi ! I'm trying to create a SearchController on the right foot. But I realized that it's not possible to use a foreach loop with a database query... So I've to use a lot of conditions and rewrite my code a lot of times... That's I obtain :

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use DB;

class SearchController extends Controller
{
    private function autocomplete($term, $table, $columns)
    {
        $results = array();
        
        if(is_array($columns) AND count($columns) == 2)
        {
            $queries = DB::table($table)
            ->where($columns[0], 'LIKE', '%'.$term.'%')
            ->orWhere($columns[1], 'LIKE', '%'.$term.'%')
            ->take(5)->get();

            foreach ($queries as $query)
            {
                $results[] = [ 'id' => $query->id, 'value' => $query->$columns[0].' | '.$query->$columns[1] ];
            }
        }
        else if(is_array($columns) AND count($columns) == 1)
        {
            $queries = DB::table($table)
            ->where($columns[0], 'LIKE', '%'.$term.'%')
            ->take(5)->get();

            foreach ($queries as $query)
            {
                $results[] = [ 'id' => $query->id, 'value' => $query->$columns[0]];
            }
        }
        else if(!is_array($columns))
        {
            $queries = DB::table($table)
            ->where($columns, 'LIKE', '%'.$term.'%')
            ->take(5)->get();
            foreach ($queries as $query)
            {
                $results[] = [ 'id' => $query->id, 'value' => $query->$columns];
            }
        }
        else
        {
            abort(503);
        }
        
        return response()->json($results);
    }

// Some use exemples
    public function searchTutorial(Request $request)
    {
        return $this->autocomplete($request->term, 'tutorials', ['title', 'creators']);
    }

    public function searchUser(Request $request)
    {
        return $this->autocomplete($request->term, 'users', 'username');
    }
}

Would anybody know how to upgrade this code ? I'm not really satisfied with this... But I don't know how to make it better.

31 Dec
2 years ago

Eluknow left a reply on One-to-many Relationship With A Same Model ?

Thanks ! I didn't know Baum. But what I want don't need any package I think, it's easy enough. Thank you @SaeedPrez

Eluknow started a new conversation One-to-many Relationship With A Same Model ?

Hi everyone ! I wonder if it was possible to do a one-to-many relationship with a same model.. In fact, I've a model called "Category". And i'd like that a category can have some sub-categories that would come from the same model... I would have something like that :

/*
    |--------------------------------------------------------------------------
    | Relationship Methods
    |--------------------------------------------------------------------------
    */
    
    /**
     * One To Many Relationship Method for accessing the subcategory->category
     * 
     * @return QueryBuilder Object
     */
    public function parent()
    {
        return $this->belongsTo('App\Models\Category', 'parent_id');
    }

    /**
    * One To Many Relationship Method for accessing the parent-category->children-categories
    *
    * @return QueryBuilder Object
     */
    public function children()
    {
        return $this->hasMany('App\Models\Category', 'parent_id');
    }

And I wonder if it was the good way to do what I want... May anyone help me ?

Eluknow left a reply on Different Controllers' Method In Another Controller

Okay I understand ! Thank you ;)

30 Dec
2 years ago

Eluknow left a reply on Different Controllers' Method In Another Controller

Thanks a lot everybody.

I return a view.

In fact, my answer was rather something like that : I wonder if it's convenient to retrieve some datas from "task model" et "tutorial model" in the same controller whereas I've already created two others controllers that handle tasks and tutorials (correspondingly).

As a result, I'd have something like (in my case) :

public function index()
    {
        $tutorials = Tutorial::latest()->limit(10)->chunk(5);
        $tasks = Task::all()->chunk(5);
        return view('backoffice.index', compact($tutorials, $tasks));
    }

@jekinney , do I correctly use my queries in this exemple ?

Once again, thanks a lot

Eluknow started a new conversation Different Controllers' Method In Another Controller

Hi ! In fact, I've two controllers : taskController and tutorialController. I'm creating a back office for my website and on his index, I display a "summary table" that contains the last tasks to do but I also display the last posted tutorials. So, I need to use the 2 controllers I quoted above... I thought I could create a third controller called, for instance, "BackOfficeController" in which I'd create an index method where I'd retrieve the tutorials and the tasks, but I think it's not... convenient.

So, I come here to ask you if you have any idea ? How would you do it ?

16 Nov
2 years ago

Eluknow left a reply on Users, Roles, Permissions, Forums

With LaravelSD, I represented what I have and how I imagine my structure. But, what's the Laravel's relationship that will able me to retrieve the permissions for foo role and for bar forum ?

Because in fact, the "forums_permission" table contains the permission, but each forum has different permissions. So, there are some forum's permissions for each role and each forum.

Does someone know what's the relationship I need ?

15 Nov
2 years ago

Eluknow started a new conversation Users, Roles, Permissions, Forums

Hi ! Tonight I've a lot of questions, sorry :p.

So, I just wondered how to organize my tables and my models in order to do the following thing :

  • I've users, who can belong to roles that have some permissions (update profile, add user, for instance). Here, I know how to do.
  • But I've also something like "forums", indeed some website's parts where roles haven't got the same permissions in each parts. For exemple, the role called "foo" can see the part "bar" and write in this part. But he cannot see "bar2" part. So, I've to find an architecture that allows me to give some permissions for some roles AND that allows me to give some permissions based on the parts for some roles... Am i understandable ? :p.

I'm going to try to explain more briefly : How to organize my tables and models in order to give to roles different permissions based on the part. A role can have the permission to update profile / add user AND to see some parts / write in some parts. So, the main problem is that I cannot create a permission called "see" because a role could has the right to see a part but doesn't be allow to see another part. I've some "fixed" permissions (add user, delete user etc) and some permissions that depend on the part.

Have you got any idea to solve the problem ? Thanks a lot !

Eluknow left a reply on Another Way To Use Repository Pattern

Okay, I understand, thank you ;).

I don't think it's good idea to post one of my controllers xD, indeed I rework all my website from A to Z, precisely because I found my codes bad. So, the code makes no sense. But what you explained me is perfect, thanks ;).

Eluknow started a new conversation Another Way To Use Repository Pattern

Hi everyone !

I try to use the Repository Pattern in my project but i've some "problems".

  • Firstly, i don't really understand why it's better to create a FooRepositoryInterface implementing RepositoryInterface and next a FooRepository using FooRepositoryInterface. Why couldn't we do just RepositoryInterface and FooRepository ?

  • Secondly, I often be obliged to instantiate 3, 4, 5 even more sometimes repositories in Controller's construct method... Is there another way to use Repositories in my controllers ?

I think I bad use repositories.. Could you give me a rough idea of how to well-use ?

Eluknow left a reply on The Better Way To Use Policies ?

Okay, I see. It really helps me. Thanks a lot guys. Bobbybouwmann : I'd like to watch Laracasts's videos, but I'm French (and too young to have a credit card that allows me to pay on websites ahah).

But I understood that there was so many ways to use it, I think i'll use them with models ;).

Thank you !

Eluknow started a new conversation The Better Way To Use Policies ?

Hi ! Because I've a lot of lines in the AuthServiceProvider's boot method, I'd like to use the policies. Nevertheless, I don't know what's the better way to use them. In fact, I don't know if I should create, for instance, a PostPolicy in which I'll put all my authorization's checks regarding the post methods or if I should create a FooPolicy in which I'll put all my authorization's checks regarding my Foo controller and do it with all of my controllers.

May you tell me what's the better way ? :) Thanks !

01 Jun
3 years ago

Eluknow left a reply on Can I Map A Domain To A User Route?

Yes, if I well understand, you can do this. I checked it in the doc :

Route::group(['domain' => '{account}.myapp.com'], function () {
    Route::get('user/{id}', function ($account, $id) {
        //
    });
});

You can add a middleware that authorizes (or not) the access for a member. So :

Route::group(['domain' => '{username}.myapp.com', 'middleware'=>'userAccess'], function () {
    Route::get('user/{id}', function ($username, $id) {
        //
    });
});

And check in your middleware if the user is allowed to see the part :)

Eluknow left a reply on Laravel Cache And Foreach

Okay, I found my error... I forgot to use "return" at the foreach's end (sorry, I don't know if it's understandable, this sentence is built as in French xD).

For those who are interested :

$tutorial->parts = Cache::remember('tutorial-'.$tutorial_id.'-parts', 5, function() use($tutorial) {
            foreach($tutorial->parts as $part)
            {
                $part->content = preg_replace('#\[code=(php|html|css|javascript|markup)\](.+)\[/code\]#isU', '<pre><code class="language-$1">$2</code></pre>', htmlentities($part->content));
                $part->content = preg_replace('#\[b\](.+)\[/b\]#isU', '<strong>$1</strong>', $part->content);
                $part->content = preg_replace('#\[img src=(.+)\](.+)*\[/img\]#isU', '<img src="$1" title="$2" alt="$2" />', $part->content);
                $part->content = preg_replace('#\[spoiler(=(.+))*\](.+)\[/spoiler\]#isU', '<section id="modal" tabindex="0"><i>$2</i><div><article><span id="close" tabindex="0"><a href="#">Fermer X</a></span><p>$3</p></article></div></section>', $part->content);
                $part->content = preg_replace('#\[i\](.+)\[/i\]#isU', '<em>$1</em>', $part->content);
                $part->content = preg_replace('#\[warning\](.+)\[/warning\]#isU', '<div class="warning">$1</div>', $part->content);
                $part->content = preg_replace('#\[info\](.+)\[/info\]#isU', '<div class="info">$1</div>', $part->content);
                $part->content = preg_replace('#\[color=(.+)\](.+)\[/color\]#isU', '<span style="color:$1;">$2</span>', $part->content);
                $part->content = preg_replace('#\[list\](.+)\[/list\]#isU', '<ul>$1</ul>', $part->content);
                $part->content = preg_replace('#\[*\](.+)\[/\*\]#isU', '<li>$1</li>', $part->content);
                $part->content = preg_replace('#\[size=(.+)\](.+)\[/size\]#isU', '<span style="font-size:$1;">$2</span>', $part->content);
                $part->content = nl2br($part->content);
            }
            return $tutorial->parts;
        });

Eluknow started a new conversation Laravel Cache And Foreach

Hi, I'd like to put tutorials's parts in the laravel cache. But i don't know how to do because i've to pass the $tutorial->parts in a foreach loop :

$tutorial = Cache::remember('tutorial-'.$tutorial_id, 1440, function() use($tutorial_id) {
            return $this->repository->getById($tutorial_id);
        });
        foreach($tutorial->parts as $part)
        {
            $part->content = preg_replace('#\[code=(php|html|css|javascript|markup)\](.+)\[/code\]#isU', '<pre><code class="language-$1">$2</code></pre>', htmlentities($part->content));
            $part->content = preg_replace('#\[b\](.+)\[/b\]#isU', '<strong>$1</strong>', $part->content);
            $part->content = preg_replace('#\[img src=(.+)\](.+)*\[/img\]#isU', '<img src="$1" title="$2" alt="$2" />', $part->content);
            $part->content = preg_replace('#\[spoiler(=(.+))*\](.+)\[/spoiler\]#isU', '<section id="modal" tabindex="0"><i>$2</i><div><article><span id="close" tabindex="0"><a href="#">Fermer X</a></span><p>$3</p></article></div></section>', $part->content);
            $part->content = preg_replace('#\[i\](.+)\[/i\]#isU', '<em>$1</em>', $part->content);
            $part->content = preg_replace('#\[warning\](.+)\[/warning\]#isU', '<div class="warning">$1</div>', $part->content);
            $part->content = preg_replace('#\[info\](.+)\[/info\]#isU', '<div class="info">$1</div>', $part->content);
            $part->content = preg_replace('#\[color=(.+)\](.+)\[/color\]#isU', '<span style="color:$1;">$2</span>', $part->content);
            $part->content = preg_replace('#\[list\](.+)\[/list\]#isU', '<ul>$1</ul>', $part->content);
            $part->content = preg_replace('#\[*\](.+)\[/\*\]#isU', '<li>$1</li>', $part->content);
            $part->content = preg_replace('#\[size=(.+)\](.+)\[/size\]#isU', '<span style="font-size:$1;">$2</span>', $part->content);
            $part->content = nl2br($part->content);
        }
        return view('front.tutorials.show')->with(['tutorial' => $tutorial, 'languages' => Language::all()]);

I tried to do like that :

$tutorial->parts = Cache::remember('tutorial-'.$tutorial_id.'-parts', 5, function() use($tutorial) {
            foreach($tutorial->parts as $part)
            {
                $part->content = preg_replace('#\[code=(php|html|css|javascript|markup)\](.+)\[/code\]#isU', '<pre><code class="language-$1">$2</code></pre>', htmlentities($part->content));
                $part->content = preg_replace('#\[b\](.+)\[/b\]#isU', '<strong>$1</strong>', $part->content);
                $part->content = preg_replace('#\[img src=(.+)\](.+)*\[/img\]#isU', '<img src="$1" title="$2" alt="$2" />', $part->content);
                $part->content = preg_replace('#\[spoiler(=(.+))*\](.+)\[/spoiler\]#isU', '<section id="modal" tabindex="0"><i>$2</i><div><article><span id="close" tabindex="0"><a href="#">Fermer X</a></span><p>$3</p></article></div></section>', $part->content);
                $part->content = preg_replace('#\[i\](.+)\[/i\]#isU', '<em>$1</em>', $part->content);
                $part->content = preg_replace('#\[warning\](.+)\[/warning\]#isU', '<div class="warning">$1</div>', $part->content);
                $part->content = preg_replace('#\[info\](.+)\[/info\]#isU', '<div class="info">$1</div>', $part->content);
                $part->content = preg_replace('#\[color=(.+)\](.+)\[/color\]#isU', '<span style="color:$1;">$2</span>', $part->content);
                $part->content = preg_replace('#\[list\](.+)\[/list\]#isU', '<ul>$1</ul>', $part->content);
                $part->content = preg_replace('#\[*\](.+)\[/\*\]#isU', '<li>$1</li>', $part->content);
                $part->content = preg_replace('#\[size=(.+)\](.+)\[/size\]#isU', '<span style="font-size:$1;">$2</span>', $part->content);
                $part->content = nl2br($part->content);
            }
        });

But it doesn't work. So, does anybody know how to do ? Thanks

17 May
3 years ago

Eluknow left a reply on Define An Order And Reindex It In MySQL

Okay, I've understood. It works. Thanks a lot, you're my sun for this rainy day :D

16 May
3 years ago

Eluknow started a new conversation Define An Order And Reindex It In MySQL

Hello ! I've got a problem and I really don't know how to solve it. I have a table containing a "order" column. This column isn't like the "id" auto-increment column. Indeed, this column is used for the SQL request (with query builders) : we take the table's datas ordered by the "order" column. And the order is updatable. And I would like it : if somebody updates the "order" of a data, all the others datas have to change their. For example : A data has got as "order" : 3 And a member updates it : 3 -> 4 The data that had the value "4" as "order" updates it as "5", those after as "6" etc. So, the previous value + 1. Do you understand ? I don't know if I am understandable :p. So, is someone able to help me ? How could I do it ? It's a reindexation in bdd.

09 May
3 years ago

Eluknow started a new conversation Integrity Constraint Violation: 1452 With Update Method

Hello ! I've a little problem today. Indeed, I receive the error indicated in the title when I only try to update datas already registered in the db. When I store the datas, I haven't got this error, it's just when I update. My code :

public function up()
    {
        Schema::create('tasks', function(Blueprint $table) {
            $table->increments('id');
            $table->timestamps();
            $table->string('title');
            $table->text('description')->nullable();
            $table->bigInteger('poster_id')->unsigned();
            $table->timestamp('end')->nullable();
            $table->bigInteger('taken_by')->unsigned()->nullable();
            $table->bigInteger('assigned_to')->nullable();
            $table->boolean('done');
        });
    }```
With the foreign key : 
```php
Schema::table('tasks', function(Blueprint $table) {
            $table->foreign('poster_id')->references('id')->on('users')
                        ->onDelete('restrict')
                        ->onUpdate('restrict');
        });
        Schema::table('tasks', function(Blueprint $table) {
            $table->foreign('taken_by')->references('id')->on('users')
                        ->onDelete('restrict')
                        ->onUpdate('restrict');
        });

And the controller's code :

public function update($id, UpdateTaskRequest $request)
    {
        $task = $this->repository->getById($id);
        $this->repository->update($task->id, $request->all());
        return redirect(url('admin/todolist'))->withOk('The task has been updated, thanks.');
    }

May somebody help me ? This error really puzzles me because the add method does work !

28 Apr
3 years ago

Eluknow started a new conversation Update A Table That Doesn't Contain Id

Hi everybody ! As I've said in the title, I have to update (and take) datas in my db. But, the table where they are doesn't contain any id. It's just a table with 3 rows. Like a pivot table : just rows without id. But it's not a pivot table. So, I'd like to know how to retrieve these datas without any id :/. And overall, how to update them ! Thanks ;)

21 Apr
3 years ago

Eluknow started a new conversation Calculations With Query Builders ?

Hi! I'd like to know if it's possible with Laravel (and query builders) to do something like this : $foo = Model::where('column1' + 'column2' > 42); And, if it's possible, how? Thanks!

17 Apr
3 years ago

Eluknow left a reply on Former Values Instead Of Recents

Okay I found. It works. Thanks a lot, really !

Eluknow left a reply on Former Values Instead Of Recents

Thanks ! Yes, I need all the exam's values, so I think use $exam->toArray(). But, how to access to array session's values in views ? I've been using {{ session('exam')->step }} since I learnt to use Laravel, and now, as you can imagine, it does not work. Have you got any idea ? I search on the web by my side.

Eluknow started a new conversation Former Values Instead Of Recents

Hi, I've got a little problem. I've that :

 public function firstpart($exam_id)
    {
        $exam = $this->repository->getById($exam_id);
        $questions = $this->questionRepository->getQuestionsForExam($exam);
        Session::put('exam', $exam);
        $exam->step = 2;
        $exam->save();
        return view('front.exams.step-questions')->with(['questions' => $questions]);
    }

Indeed, I put $exam in session because I wanna pass to view the former values, just before I change the $exam->step to 2. I have to pass to view the $exam with $exam->step = 1, but I also have to change the step in db. So, I tried it (session) but even that doesn't work : session('exam') contains 'step' = 2 So, how can I do what I have to do ? Thanks to those who'll help me !

12 Apr
3 years ago

Eluknow left a reply on Class Cookie Does Not Exist Laravel 5.2

I believe that cookies are used with the "web" middleware. Are you sure you use this middleware in your route in which you've got your error ?

Eluknow left a reply on Class Cookie Does Not Exist Laravel 5.2

Hi, What's the error you've got ?

Eluknow left a reply on Form Validation

Okay, thanks a lot, it perfectly works.

11 Apr
3 years ago

Eluknow left a reply on Form Validation

Oh I didn't know this Laravel's method. Thanks ! I'll try it tomorrow.

Eluknow started a new conversation Form Validation

Hi, I'd like to improve my code. Every time I have an update form, I check if the form value is different than the value registered in the db. For exemple, for the update form for users, when a user submit the form, I check if the password is different than which registered in the db. I do the same thing for each values. In order to do it, I do all the verifications in the controller like this :

public function update(UserUpdateRequest $request, $user_id)
    {
        $user = $this->repository->getById($user_id);
        $updates = 0; //Nb of modifications
        if($user->username !== $request->username)
        {
            $updates++;
        }
        if($user->id_forum != $request->id_forum)
        {
            $updates++;
        }
        if($user->password != bcrypt($request->password) AND !empty($request->password))
        {
            $updates++;
        }

        if($updates > 0)
        {
            $this->repository->update($user->id, $request->all());
            $ok = 'L\'utilisateur a bien été modifié !';
        }
        else
        {
            $ok = '';
        }

        return redirect(url('admin/user/edit/'.$user->id))->with('ok', $ok);
    }

I'd like to know if there is another way to do this. I'd thought to do the verification in the UserUpdateRequest, but I don't know how. I've seen the available validation rule "different" in the doc but I don't know how to use it in my case. Is someone available to help me ? :) Thanks and good night !

Eluknow left a reply on Relationship Between Two Models

Yes, a Training only has got one Language and a Language has more than one training. Okay, I thougth it wasn't. Thanks a lot !

Eluknow left a reply on Relationship Between Two Models

Okay, I'd thought easier. Perhaps too easy ahah.

Otherwise, in term of logic, the following way is correct ?

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Training extends Model
{
    protected $table = 'trainings';

    public function language()
    {
        return $this->belongsTo('App\Language');
    }
}

It works well, but I think it's not correct, it's just a simple solution for lazy guys like me xD. Thanks for answering me !

Eluknow left a reply on Catch (PDO) Exceptions And Return A View

Hi, Except if I didn't understand your problem, I think this code can help you :

try{
// Your pdo command
$status = $req->execute ();
} catch(PDOException $e)
{
print $e->getMessage();
}
print $status; 

And don't forget to put this :

$connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

while you're connecting to the db

Is this helped you ? If not, sorry, I think I misunderstood your pb Have a nice evening!

Eluknow started a new conversation Relationship Between Two Models

Hi, I've a little problem. I don't know what's the relationship between two of my models. My two models are "Training" and "Language". One training has got one language but a language can be used in some trainings. So, I have a "language_id" column on my "trainings" table, that matches with a language's id. I've thought the relationship between my two models would be a One to Many but no. Indeed, it doesn't work... I've that error : SQLSTATE[42S22]: Column not found: 1054 Unknown column 'languages.training_id' in 'where clause' (SQL: select * from languages where languages.training_id = 1 and languages.training_id is not null limit 1) (View: /Applications/MAMP/htdocs/atdc/resources/views/admin/trainings/show.blade.php)

So I've understood that with this code :

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Training extends Model
{
    protected $table = 'trainings';

    public function language()
    {
        return $this->hasOne('App\Language');
    }
}```
Eloquent will search in the Database a column training_id on the languages table, instead of (what I want) searching a column language_id in the trainings table. 
In term of logic, it'd be better that I can access to the trainings' language by the following code : App\Training::find($id)->languages but I don't know how to have this with my table configuration...
May someone help the little man I am ? Ahah
Good evening and thanks ! 
09 Apr
3 years ago

Eluknow left a reply on Auth And Permissions

Oh, thanks a lot ! I didn't see ! It should help me out a lot, ye !

Eluknow left a reply on Where Are You All From?

In the deepest countryside of the world in France. You cannot imaginate a countryside so deep xD. Okay, I live in Nevers, France !