Rainn

Rainn

Member Since 1 Year Ago

Experience Points
2,810
Total
Experience

2,190 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
26
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.

Level 1
2,810 XP
Jul
30
3 months ago
Activity icon

Started a new Conversation How Can I Change The Order ID Of My Categories Using SortableJS For JQuery, And AJAX?

I am trying to use this JavaScript library called SortableJS along with jQuery & jQuery SortableJS. I have the front-end functionality working, but my issue is trying to get it to work successfully with an AJAX request.

JavaScript

<script src="https://cdn.jsdelivr.net/npm/[email protected]/Sortable.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/jquery-sortable.js"></script>
<script>
$(document).ready(function(){
    $("#sortable-cards").sortable({
        animation: 350,
        easing: "cubic-bezier(1, 0, 0, 1)",
        stop: function() {
            $.map($(this).find('.col-lg-4'), function(el) {
                var id = el.id;
                var order = $(el).index();
                $.ajax({
                    url: '{{route('manage.orderCategories')}}',
                    type: 'POST',
                    data: {
                        id: id,
                        order: order
                    },
                });
            });
        }
    });
});
<script>

Sortable Cards Div in my Blade File

<div id="sortable-cards" class="row justify-content-center">
    @foreach($categories as $category)
    <div id="{{$category->order}}" class="col-lg-4 col-12 mt-4">
        <div class="card shadow">
            <div class="card-body">
                <h3>{{$category->name}}
                <p class="text-muted">{{$category->description}}<p>
                ID: {{$category->id}}<br>
                Order: {{$category->order}}<br>
            </div>
        </div>
    </div>
    @endforeach
</div>

Routes

Route::post('categories/orderCategories', 'Manage\[email protected]')->name('orderCategories');

Controller

public function orderCategories()
{
    $categories = Category::orderBy('order', 'ASC')->get();
    $id = Input::get('id');
    $order = Input::get('order');
    foreach ($categories as $item) {
        return Category::where('id', '=', $id)->update(array('order' => $order));
    }
}

The expected result is that when a sortable card is moved it will send an AJAX request to the controller and update the 'order' column in the database. Like I mentioned before the front-end functionality works fine, and there were no error messages present. If you need more information please let me know. Thank you for your help

Jul
11
4 months ago
Activity icon

Replied to Custom Form Validation Is Not Working For Some Reason

@nakov That did the trick, thank you.

Activity icon

Started a new Conversation Custom Form Validation Is Not Working For Some Reason

I am using custom form validation for my replies using toastr. For some reason the validation does indeed kick in by displaying the toastr notification example. But it won't stop the user from creating a reply.

I've tried overriding stock validation functions such as: formatValidationErrors() and failedValidation() The second function was the only one to work (displays the toastr notification), but it gave me the issue above.

App\Http\Controllers\ReplyController.php

Here is the store method. The ThreadReceivedReply event is included at the top of the file.

public function store(Thread $thread, ReplyForm $form)
{
    if (Gate::denies('create', new Reply)) {
        toastr()->error('You are creating too many replies. Please wait 30 seconds', 'Slow Down');
        return back();
    }
    
    $reply = Reply::create([
        'body' => Purifier::clean(request('body')),
        'user_steamid' => auth()->user()->steamid
    ]);

    event(new ThreadReceivedReply($reply));

    if($reply->user_steamid != $thread->user_steamid) {
        $thread->user->notify(new RepliedToThread($thread));
    };

    $thread->replies()->save($reply);

    Cache::forget('replies');

    toastr()->success('Reply created. Nice job');
    return back();
}

App\Http\Forms\ReplyForm.php

<?php

namespace App\Http\Forms;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Contracts\Validation\Validator;

class ReplyForm extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true; // testing
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'body' => 'required|max:1000|spamfree'
        ];
    }

    public function messages()
    {
        return [
            'body.required' => 'Your reply needs body text!'
        ];
    }

    protected function failedValidation(Validator $validator)
    {
        
        $messages = $validator->messages();

        foreach ($messages->all() as $message)
        {
            toastr()->error($message, 'Woops');
        }

        return $validator->errors()->all();
    }
}

I was sort of going off of this post to try to fix the issue but it didn't get me very far. The expected outcome is when you don't input body information it will display that validation error as a toast. I would show you errors but none were displayed. If you need any more information please don't hesitate to ask me. Thank's for your help in advance!

Jul
09
4 months ago
Activity icon

Replied to How Can I Use A Trait (or Anything That Can Fix My Issue) In This Instance.

Fixed the issue with:

$configurables = Cache::rememberForever('configurables', function() {
            return Configurables::all();
        });

        $configurable = [];

        foreach($configurables as $key) {
            $configurable[$key->slug] = [
                'value' => $key->value
            ];
        }

       $view->with('configurable', $configurable);
Activity icon

Replied to How Can I Use A Trait (or Anything That Can Fix My Issue) In This Instance.

Your code above didn't seem to work, although it looks like it should.

Here is a little more information about the $configurable variable. It isn't just used for site_name. Ex)

$configurable['site_name']['value']
$configurable['logo']['value']
$configurable['siteurl']['value']

and the list goes on.

And I apologize for my lack of understanding, still learning.

Activity icon

Replied to How Can I Use A Trait (or Anything That Can Fix My Issue) In This Instance.

I tried these 2 ways

foreach($configurables as $key) {
   $configurable[$key->slug] = [
          'value' => $key->value
   ];
};
return $configurable = [];

and

foreach($configurables as $key) {
   $configurable[$key->slug] = [
          'value' => $key->value
   ];
};
$configurable = [];

both ways still return the same error

Activity icon

Replied to How Can I Use A Trait (or Anything That Can Fix My Issue) In This Instance.

@nakov Thank you for your help. So far View Composers are working like a charm!

I am running into one issue, however.

public function configurables(View $view)
    {
        $view->with('configurable', function() {
            $configurables = Cache::rememberForever('configurables', function() {
                return Configurables::all();
            });
            $configurable = [];
            foreach($configurables as $key) {
                $configurable[$key->slug] = [
                    'value' => $key->value
                ];
            };
        });
    }

Is not working because I am using it as $configurable[key']['value'] in the actual view. Here is the error: "Cannot use object of type Closure as array"

Again, thank you for your help so far!

Jul
08
4 months ago
Activity icon

Started a new Conversation How Can I Use A Trait (or Anything That Can Fix My Issue) In This Instance.

Hello, I am currently in the process of refactoring my controllers, and I have a piece of code that is present in nearly all of my controllers and almost every function.

This is what my code currently is right now, pretty much in every controller, here is an example:


    $objectone  =  Cache::rememberForever('objectone',  function()  {
        
        return  ObjectOne::all();
       
    });
       
    $objecttwo  =  Cache::rememberForever('objecttwo',  function()  {
       
        return  ObjectTwo::all();
       
    });
       
    $objectthree  =  Cache::rememberForever('objectthree',  function()  {
       
        return  ObjectThree::all();
       
    });
    $users  =  User::orderBy('created_at',  'desc')->paginate(12);
    return  view('users.index',  compact('users'))->with(compact('objectone',  'objecttwo',  'objectthree'));

This is the code I am trying to get into a trait of some sort:

    $objectone  =  Cache::rememberForever('objectone',  function()  {
    
        return  ObjectOne::all();
    
    });
    
    $objecttwo  =  Cache::rememberForever('objecttwo',  function()  {
    
        return  ObjectTwo::all();
    
    });
    
    $objectthree  =  Cache::rememberForever('objectthree',  function()  {
    
        return  ObjectThree::all();
    
    });

The only issue is that if I do create a Trait and put this code into a function this doesn't work anymore:

return view('users.index', compact('users'))->with(compact('objectone', 'objecttwo', 'objectthree'));

Because I am trying to return the view of "users.index" with users. But since objectone, objecttwo, and objectthree is in a Trait it will not work in this instance.

What I have tried:

App/Traits/SimpleIncludes.php

    use App\Models\ObjectOne;
    use App\Models\ObjectTwo;
    use App\Models\ObjectThree;
    use Illuminate\Support\Facades\Cache;
    
    trait  SimpleIncludes
    {
        public function method()
        {
            $objectone  =  Cache::rememberForever('objectone',  function()  {
            
                return  ObjectOne::all();
            
            });
            
            $objecttwo  =  Cache::rememberForever('objecttwo',  function()  {
            
                return  ObjectTwo::all();
            
            });
            
            $objectthree  =  Cache::rememberForever('objectthree',  function()  {
            
                return  ObjectThree::all();
            
            });
        }
    }

App/Http/Controller/UsersController.php

    use  App\Traits\SimpleIncludes;
    
    class UsersController extends Controller
    {
        use SimpleIncludes;
        public  function  index()
        {
            $data = $this->method();
            $users  =  User::orderBy('created_at',  'desc')->paginate(12);
            return  view('users.index',  compact('users'))->with($data));
        }
    }

^ Does not work, displays that the variables on the view ($objectone,two,three) do not exist

Here is the synopsis of the issue: I have a block of code that is used in nearly ever controller, and every function within that controller. I wish to take that block of code out and put it into a trait of some sort so that it isn't manually placed in every controller.

If you got confused reading this please don't hesitate to ask questions I will provide you with as much information as I can.