Kusanagi

Member Since 1 Month Ago

Experience Points
540
Total
Experience

4,460 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 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.

  • Community Pillar

    Earned once your experience points ranks in the top 10 of all Laracasts users.

Level 1
540 XP
Mar
13
1 month ago
Activity icon

Started a new Conversation Add To Auth::user()->favorite

Hello,

I have a website where a user can log in. For that I have a database "users". I can access the data from "users" like this :

@guest
@else
{{Auth::user()->name}}
@endguest

the database "users" also contains a column "favorites" where users can add their favorite image ( the name of the image get added ).

I want to make a button that can add the name of the image to "favorites" I though about doing it this way:

@guest
@else
                {{Auth::user()->favorite = Auth::user()->favorite ."img_name,"}}
                {{Auth::user()->save}}
@endguest

But that did not work. Does anyone have an idea how to make it work ?

Thank you in advance

Mar
12
1 month ago
Activity icon

Replied to Change Value Is Database

Thank you all, it worked :D

Activity icon

Replied to Change Value Is Database

my table is: name, views, description I dont have a primary key. How can I add one with sql ?

Activity icon

Replied to Change Value Is Database

@tykus @chaudigv I got this error

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'id' in 'where clause' (SQL: update `list` set `views` = 10 where `id` is null)

this is my code :

foreach (list::all() as $pages){
            if ($pages->name == $page){
                $pages->views = $pages->views +1;
                $pages->save();
            }
        }
Activity icon

Started a new Conversation Change Value Is Database

Hello,

How can I change a value is my database ?

I tried this :

$page->views = $page->views +1;

But that did not work xD

Mar
07
1 month ago
Activity icon

Replied to Foreach, Variable "id" For Each Item ?

@vincent15000

this is what I have :

<style>
    #more {
        display: none;
    }
</style>

@section('main')
<script
            src="https://code.jquery.com/jquery-3.6.0.slim.js"
            integrity="sha256-HwWONEZrpuoh951cQD1ov2HUK5zA5DwJ1DNUXaM6FsY="
            crossorigin="anonymous">
            $(".more").click(function(e) {
                e.preventDefault();
                let id = $(this).attr("more_id");
                $("#more-"+id).show(150);
            });
        </script>
@foreach($items as $item)

<p><span more_id="{{ $loop->index }}" class="more">...</span><span id="more-{{ $loop->index }}">{{$item['Description']}}</span></p>

                    <button onclick="show_desc()" id="myBtn-{{ $loop->index }}">Show Description</button>

@endforeach
@endsection

What did I do wrong ?

Activity icon

Replied to Show More Button In @foreach

@tykus so this is what I have now :

<style>
    .more {
        display: none;
    }
</style>
.
.
.
<main>
@foreach($itemst as $item)
<p><span class="dots">...</span><span class="more">{{$item['Description']}}</span></p>
<button onclick="show_desc()" class="myBtn">Show Description</button>
@endforeach
</main>
      <script>
            function show_desc() {
                var dots = document.querySelector("dots");
                var moreText = document.querySelector("more");
                var btnText = document.querySelector("myBtn");

                if (dots.style.display === "none") {
                    dots.style.display = "inline";
                    btnText.innerHTML = "Show Description";
                    moreText.style.display = "none";
                } else {
                    dots.style.display = "none";
                    btnText.innerHTML = "Hide Description";
                    moreText.style.display = "inline";
                }
            }
        </script>

The button does not work. What did I do wrong ?

Activity icon

Replied to Foreach, Variable "id" For Each Item ?

@vincent15000 it doesn't work :/ the description is shown and the button does nothing.

Activity icon

Started a new Conversation Show More Button In @foreach

Hello,

I have a database which contains a lot of text.

I want to show that text and I did that while iterating over each text with "foreach".

I wanted to add a "show more" button. I did it with this script :

<script>
    function show_desc() {
                    var dots = document.getElementById("dots");
                    var moreText = document.getElementById("more");
                    var btnText = document.getElementById("myBtn");

                    if (dots.style.display === "none") {
                        dots.style.display = "inline";
                        btnText.innerHTML = "Show Description";
                        moreText.style.display = "none";
                    } else {
                        dots.style.display = "none";
                        btnText.innerHTML = "Hide Description";
                        moreText.style.display = "inline";
                    }
                }
            </script>

in my html part I have :

@foreach ($items as $item)
     <p><span id="dots">...</span><span id="more">{{$item['Description']}}</span></p>
@endforeach

I also have a css property :

    .more {
        display: none;
    }

The problem is that the "show more" button only works for the first element. This is because my x items that I show with foreach all get the same "id".

I know the problem but I don't know the solution.

Can anyone help me please

Mar
05
1 month ago
Activity icon

Replied to Foreach, Variable "id" For Each Item ?

@vincent15000 I don't know how to work with jQuery. I tried coping your code but that did not work for me.

Mar
04
1 month ago
Activity icon

Replied to Foreach, Variable "id" For Each Item ?

Hello @vincent15000 thank you for your answer.

I changed id to class and getElementById to getElementsByClassName. Now not even the first works xD

Activity icon

Started a new Conversation Foreach, Variable "id" For Each Item ?

Hello,

I have a database which contains a lot of text.

I want to show that text and I did that while iterating over each text with "foreach".

I wanted to add a "show more" button. I did it with this script :

                function show_desc() {
                    var dots = document.getElementById("dots");
                    var moreText = document.getElementById("more");
                    var btnText = document.getElementById("myBtn");

                    if (dots.style.display === "none") {
                        dots.style.display = "inline";
                        btnText.innerHTML = "Show Description";
                        moreText.style.display = "none";
                    } else {
                        dots.style.display = "none";
                        btnText.innerHTML = "Hide Description";
                        moreText.style.display = "inline";
                    }
                }
            </script>

in my html part I have :

@foreach ($items as $item)
     <p><span id="dots">...</span><span id="more">{{$item['Description']}}</span></p>
@endforeach

The problem is that the "show more" button only works for the first element. This is because my x items that I show with foreach all get the same "id".

I know the problem but I don't know the solution.

Can anyone help me please

Mar
03
1 month ago
Activity icon

Started a new Conversation Access Sort Array From Database

Hello,

I have a table in my database with 2 columns : "name" and "views". I want to display it ordered by views from most views to least. I have a model called "list" which accesses the database. In my controller I wrote my_list = list::all()->toArray(); this gives me back my database in form of an array. if I print_r($list[0]); I get : "Array ( [name] => name [views] => 10 ) ". I tried to sort the array with usrot.

My Problem is that list[0]->views does give me the following error Trying to get property 'views' of non-object How can I solve this Problem ?

Activity icon

Replied to Sort File::files(public_path('img'))

thx a lot. It worked :D. Could you please explain to me why array($this, 'my_compare') worked and what I did, did not ?

Activity icon

Replied to Sort File::files(public_path('img'))

Thank you for your help, I tried what you told me but I got this error :

usort() expects parameter 2 to be a valid callback, class 'controller_class' not found

I tried to implement it like this, since both the function my_compare and the usort are in the same controller :

usort($files, "my_compare");

but then I got this error : usort() expects parameter 2 to be a valid callback, function 'my_compare' not found or invalid function name

I am not sure where the problem might be

Mar
02
1 month ago
Activity icon

Started a new Conversation Sort File::files(public_path('img'))

Hello I have a folder containing images and I want to show them on my page. So I did this

@foreach (File::files(public_path('img')) as $file)

            <img src="/img/{{ $file->getFilename() }}"/>

        @endforeach

The problem is as follows:

the name of the images are img_1, img_2,....,img_90

On my website the images get shown in this order : img_1, img_10, img_11, ..., img_2, img_20 etc. I want them to be in this order : img_1, img_2, img_3 etc.

How can I do this ?

Activity icon

Replied to Show All Imgs From Folder

is there a way to show them in order ? Right now they are shown in this order : img_1 img_10 img_11 ... img_19 img_2 img_20 img_21 etc. I want them to be in this oder : img_1 img_2 img_3

Activity icon

Replied to Show All Imgs From Folder

Thank you, it worked. Although I had to use $file->getFilename()

Activity icon

Started a new Conversation Show All Imgs From Folder

Hello, so I wanted to show all images from a certain directory on my page. The images that I want to show are in the folder "public". I tried :

 @foreach(Storage::files("/img/{{$folder}}") as $file)
            <img src="{{ $file }}">
@endforeach

but that did not work for me.

What did I do wrong ?

Mar
01
1 month ago
Activity icon

Started a new Conversation Variable URL & Show All .jpgs Of Certain Folder ??

Hello, sorry I am new to laravel and php in gerneral so I apologise in advance if my question is weird. So my situation is as follows : I have 300 folders, named 1 - 2 - 3 - ... - 300. Each folder contains imgs. I want to create a website as such that when I type the url : /folder_1 all imgs of my folder 1 get shown and when I type the url /folder_2 all imgs of my folder 2 get shown etc. One method would be making 300 controllers where each controller direct to one of the 300 views, and each view shows exactly the images of the corresponding folder. My questions are: 1 ) is there a method that allows me to not create the 300 controllers / views ( I know I can make it with get such as : /folder?1, but I want that is someone googles folder 1 my webpage appears so I can't do it with get ) ? 2 ) is there a simple php method that allows me to show all images of a certain directory in alphabetical order ?

Thank you all for your time :D