RFFRED

RFFRED

Member Since 11 Months Ago

Experience Points
5,460
Total
Experience

4,540 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
40
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 2
5,460 XP
Dec
15
2 months ago
Activity icon

Started a new Conversation Fake Relation When Form Fails To Submit A Repeater Fields

Hi,

I am trying to build a form that can handle repeater fields. I am no expert and this is bit hard to explain, but in essence I have a page model linked to a template model and my templates have allocated modules.

I have a testimonial module made of a 2 models: TestimonialRepeaters and testimonials

I have it all working but it feels a bit clumsy.

template model

public function init(Array $page_data)
    {

        //creates a row for the page in testimonialrepeater table
        $obj = TmTestimonialRepeater::firstOrCreate(['page_id' => $page_data['page']['id']]);

    //loads the testimonials from the database
        $data['testimonialsRepeaters'] = $obj::with(['hasTestimonials'])->get();



        //accessing the current request via the request() helper 
        $request = request();

    //gets form errors, if any
        $errors = \Session::get('errors');
  
        if (is_null($errors)) {

            //collects the records related to the page we edit
        //$page_data['page'] is the page object we edit
            $data['testimonials'] = $page_data['page']->Testimonials()->get();

        //else if the page is posted AND has errors
        } else {

            //collects fields from form
            $ids = old('testimonial_id');
            $comments =old('testimonial_comment');

            $testimonials = array_map(null, $ids, $comments);

            //creates a collection of records from an array
            $collection = collect([]);

            foreach($testimonials as $testimonial)
            {
                $model = new TmTestimonial;
                $model->id = $testimonial[0];
                $model->comment = $testimonial[1];

                //append model to collection
                $collection[] = $model;

            }
            
            $data['testimonialsRepeaters'] = $obj::with(['hasTestimonials' => $collection]);

        }

        $data['config'] = \Config::get('tm-testimonials');

        return $data;

    }

template

@foreach ($page_data['modules_data']['tm-testimonials']['testimonialsRepeaters'] as $testimonialRepeater)
        
            {!! Form::text('testimonials_title', $testimonialRepeater->title, ['class' => 'form-control', 'placeholder' => 'title']) !!}

            @foreach ($testimonialRepeater->hasTestimonials as $testimonial)

                  <tr>
                    <td>
                      {!! Form::hidden('testimonial_id[]', $testimonial->id ) !!}
                      {!! Form::text('testimonial_comment[]', $testimonial->comment, ['class' => 'form-control', 'placeholder' => 'Comment']) !!}
                   </td>
                    <td><button type="button" name="remove" class="btn btn-danger remove">Remove</button></td>
                  </tr>

            @endforeach

         @endforeach

The line I am struggling with is in the template model

$data['testimonialsRepeaters'] = $obj::with(['hasTestimonials' => $collection]);

When the form fails to submit, I want compile the testimonials posted from the form and want to add them in the "hasTestimonials" relation.

Is there a way to do this?

Activity icon

Replied to Accessing $request->validated() From A Model

What would be the best way to pass validated data to a model?

Activity icon

Started a new Conversation Form: Accessing A Model From Another Model

Hello,

I have a form calling several external modules.

In my page controller

public function edit(Request $request, Page $page)
{

        //Loads the page template which in turn loads the modules
        $page_data = $page->template()->first()->load_template_modules_data(Array('page' => $page));
  
        return view('rf-pages::admin.pages.edit', compact('page', 'page_data','request'))->withInput($request->input());

}

In my template model

    public function load_template_modules_data(array $data)
    {

        //Fetches the modules allocated to the template
        $template_modules = $this->get_modules();

        $modules_data = [];

        //for each module, compiles class names, extra info
        foreach($template_modules as $module)
        {
            
            $module_name = $module->module_name;

            $module_config_data = \Config::get($module_name);
            $module_onload_class = $module_config_data['onload'];

            //model loaded when the module starts
            $module = new $module_onload_class;
            
            // Initialise the module, load data from the database related to the page
            $modules_data[$module_name] = $module->init(array('page' => $data['page']));

        }

    //return all the modules used with information about display, functionality, visibility
        return array('template_modules' => $template_modules, 
                     'modules_data' => $modules_data);

    }

Is there a better way for the "template" model to know which "page" is doing the call without passing it as a function parameter?

Activity icon

Started a new Conversation Accessing $request->validated() From A Model

Hi

I don't seem to be able to do this from a model when submitting a form

$request = request(); //works
$validatedData = $request->validated(); //fails

My form requires several external modules which have their own saving mechanism. I would like the modules to have access to the $request->validated() function to get the submitted data.

The error I receive is:

Method Illuminate\Http\Request::validated does not exist.

I ended up passing the validated data as a function parameter but I would rather not

Dec
09
2 months ago
Dec
06
2 months ago
Activity icon

Replied to Repeated Fields

Thanks for the links but I have all my relationships already setup and working fine.

I need help when it comes to bring it to life in blade. I am able to send the collection of items to Blade, display them, add/remove items, but I am not sure what to do when the form fails to submit. Seems like there is a little bit of JS involved. It would have been nice to see a tutorial to speed up development

Activity icon

Replied to Repeated Fields

Would you mind giving a URL to look at. I must not be googling for the right thing.

Activity icon

Started a new Conversation Repeated Fields

Hi,

What is the best way to handle repeated fields in Laravel? I have all the relationships working, all the necessary JS to add/remove the fields, It just does not seem there is any decent tutorial about it. I am looking for something that loads items from the database and displays validation errors.

Any help appreciated at all.

Cheers Fred

Dec
05
2 months ago
Activity icon

Replied to Issue With Spatie/laravel-medialibrary

I got it work eventually. I deleted manually the config.php file in bootstrap/config, ran a composer update and no error.

Activity icon

Replied to Issue With Spatie/laravel-medialibrary

I run PHP 3.2

I will review the link you sent. Seems to be right on the money. I'll see if I can fix it and post an update later

Activity icon

Replied to Issue With Spatie/laravel-medialibrary

@HimanshuRajvanshi

I removed the module and tried to install it again.

I did a composer update. All was fine. Then I added the medialibrary triggering the issue Then I ran "composer update" which does not solve the issue

C:\projects\projects\fcms1>composer update
Loading composer repositories with package information
Updating dependencies (including require-dev)
Nothing to install or update
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi
Discovered Package: alexusmai/laravel-file-manager
Discovered Package: barryvdh/laravel-debugbar
Discovered Package: beyondcode/laravel-dump-server
Discovered Package: fideloper/proxy
Discovered Package: intervention/image
Discovered Package: kalnoy/nestedset
Discovered Package: laracasts/flash
Discovered Package: laravel/telescope
Discovered Package: laravel/tinker
Discovered Package: laravelcollective/html
Discovered Package: maatwebsite/excel
Discovered Package: nesbot/carbon
Discovered Package: nunomaduro/collision
Discovered Package: rfcms/client-core-settings
Discovered Package: rfcms/rf-core-settings
Discovered Package: rfcms/rf-pages
Discovered Package: rfcms/rf-redirects
Discovered Package: rfcms/rf-sitemap
Discovered Package: rfcms/rf-standard-content
Discovered Package: rfcms/rf-templates
Discovered Package: rfcms/rf-tm-page-settings
Discovered Package: rfcms/rf-tm-page-settings-siteabc
Discovered Package: rfcms/rf-tm-testimonials
Discovered Package: rfcms/rf-tm-top-banner
Discovered Package: rfcms/roles-permissions
Discovered Package: spatie/laravel-permission
Discovered Package: spatie/laravel-sitemap
Discovered Package: waavi/sanitizer
Discovered Package: yajra/laravel-datatables-buttons
Discovered Package: yajra/laravel-datatables-editor
Discovered Package: yajra/laravel-datatables-fractal
Discovered Package: yajra/laravel-datatables-html
Discovered Package: yajra/laravel-datatables-oracle
Package manifest generated successfully.

C:\projects\projects\fcms1>composer require "spatie/laravel-medialibrary:^7.0.0"
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 4 installs, 0 updates, 0 removals
  - Installing spatie/pdf-to-image (1.2.2): Loading from cache
  - Installing myclabs/php-enum (1.7.2): Loading from cache
  - Installing maennchen/zipstream-php (1.2.0): Loading from cache
  - Installing spatie/laravel-medialibrary (7.16.0): Loading from cache
spatie/laravel-medialibrary suggests installing league/flysystem-aws-s3-v3 (Required to use AWS S3 file storage)
spatie/laravel-medialibrary suggests installing php-ffmpeg/php-ffmpeg (Required for generating video thumbnails)
Writing lock file
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi

   Symfony\Component\Debug\Exception\FatalThrowableError  : Class name must be a valid object or a string

  at C:\projects\projects\fcms1\vendor\spatie\laravel-medialibrary\src\MediaLibraryServiceProvider.php:33
    29|         ], 'views');
    30|
    31|         $mediaClass = config('medialibrary.media_model');
    32|
  > 33|         $mediaClass::observe(new MediaObserver());
    34|
    35|         $this->loadViewsFrom(__DIR__.'/../resources/views', 'medialibrary');
    36|     }
    37|

  Exception trace:

  1   Spatie\MediaLibrary\MediaLibraryServiceProvider::boot()
      C:\projects\projects\fcms1\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php:32

  2   call_user_func_array([])
      C:\projects\projects\fcms1\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php:32

  Please use the argument -v to see more details.
Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 1

C:\projects\projects\fcms1>composer update
Loading composer repositories with package information
Updating dependencies (including require-dev)
Nothing to install or update
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi

   Symfony\Component\Debug\Exception\FatalThrowableError  : Class name must be a valid object or a string

  at C:\projects\projects\fcms1\vendor\spatie\laravel-medialibrary\src\MediaLibraryServiceProvider.php:33
    29|         ], 'views');
    30|
    31|         $mediaClass = config('medialibrary.media_model');
    32|
  > 33|         $mediaClass::observe(new MediaObserver());
    34|
    35|         $this->loadViewsFrom(__DIR__.'/../resources/views', 'medialibrary');
    36|     }
    37|

  Exception trace:

  1   Spatie\MediaLibrary\MediaLibraryServiceProvider::boot()
      C:\projects\projects\fcms1\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php:32

  2   call_user_func_array([])
      C:\projects\projects\fcms1\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php:32

  Please use the argument -v to see more details.
Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 1

Any ideas? or suggestion? As it is a very popular module, I am surprised I get this error

Dec
04
2 months ago
Activity icon

Started a new Conversation Issue With Spatie/laravel-medialibrary

Hello,

I am having issues installing the spatie/laravel-medialibrary . Running composer :

composer require "spatie/laravel-medialibrary:^7.0.0"

gives me

Generating optimized autoload files

Illuminate\Foundation\ComposerScripts::postAutoloadDump
@php artisan package:discover --ansi

Symfony\Component\Debug\Exception\FatalThrowableError : Class name must be a valid object or a string

at C:\projects\projects\fcms1\vendor\spatie\laravel-medialibrary\src\MediaLibraryServiceProvider.php:33
29| ], 'views');
30|
31| $mediaClass = config('medialibrary.media_model');
32|

33| $mediaClass::observe(new MediaObserver());
34|
35| $this->loadViewsFrom(DIR.'/../resources/views', 'medialibrary');
36| }
37|

Exception trace:

1 Spatie\MediaLibrary\MediaLibraryServiceProvider::boot()
C:\projects\projects\fcms1\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php:32

2 call_user_func_array([])
C:\projects\projects\fcms1\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php:32

Please use the argument -v to see more details.
Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 1
```

I have logged an issue on Github, but who knows when anyone will look at it.

Anyway, has anyone reading this experienced this issue lately?

I am on Laravel 6.6

Cheers