Asked  7 Months ago    Answers:  5   Viewed   32 times

Laravel 4.2 has the option to specify a custom view in app/config/view.php such as:

/*
|--------------------------------------------------------------------------
| Pagination View
|--------------------------------------------------------------------------
|
| This view will be used to render the pagination link output, and can
| be easily customized here to show any view you like. A clean view
| compatible with Twitter's Bootstrap is given to you by default.
|
*/
'pagination' => 'pagination_slider-alt'

This is gone in Laravel 5 at least regarding view.php.

Is there a way to replicate this behavior in Laravel 5?

 Answers

38

Whereas in Laravel 4.2 I would use:

{{ $users->links('view.name') }}

In Laravel 5 you can replicate the above with the following:

@include('view.name', ['object' => $users])

Now in the included view, $object will have the pagination methods available, such as currentPage(), lastPage(), perPage(), etc.

You can view all methods available at http://laravel.com/docs/5.0/pagination

Wednesday, March 31, 2021
 
o_flyer
answered 7 Months ago
89

Keep your session and cache separate.

In the file configdatabase.php

You can set many redis connections, by default there is a "default" but you can add more to it

let's say you created 'session-connection' and 'cache-connection'

now you need to make use of it

go to file 'configsession.php'

and set it to 'connection' => 'session-connection',

then go to file configcache.php

and set it to

    'redis' => [
        'driver'     => 'redis',
        'connection' => 'cache-connection',
    ],

and now you can get your redis session records.

use IlluminateSupportFacadesRedis;
Log::debug( Redis::connection('session-connection')->keys('*') );
Saturday, May 29, 2021
 
saad
answered 5 Months ago
10

If you read the error, it's telling you your class is not compatible with CanResetPassword. If you look at that....

interface CanResetPassword
{
    /**
     * Get the e-mail address where password reset links are sent.
     *
     * @return string
     */
    public function getEmailForPasswordReset();
    /**
     * Send the password reset notification.
     *
     * @param  string  $token
     * @return void
     */
    public function sendPasswordResetNotification($token);
}

You can see the function sendPasswordResetNotification should only take one parameter, $token. So you need to remove Request $request as a parameter from the method's signature.

In order to get the request, you will want to use the function request() inside the sendPasswordResetNotification method.

public function sendPasswordResetNotification($token)
{
    Mail::to(request()->email)->send(new newpassword($token));
}
Saturday, May 29, 2021
 
kensil
answered 5 Months ago
44

I don't think it's possible to use only function when you have code in your classes. Well, you could try with extending Blade but it's too much.

What you should do is creating one extra file, for example appHelpershelpers.php and in your composer.json file put:

"autoload": {
    "classmap": [
        "database"
    ],
    "psr-4": {
        "App\": "app/"
    },
    "files": ["app/Helpers/helpers.php"] // <- this line was added
},

create app/Helpers/helpers.php file and run

composer dump-autoload

Now in your app/Helpers/helpers.php file you could add those custom functions for example like this:

if (! function_exists('fooBar')) {
   function fooBar() 
   {
      return AppHelpersCustomHelper::fooBar();
   }
}

so you define global functions but in fact all of them might use specific public methods from some classes.

By the way this is exactly what Laravel does for its own helpers for example:

if (! function_exists('array_add')) {
    function array_add($array, $key, $value)
    {
        return Arr::add($array, $key, $value);
    }
}

as you see array_add is only shorter (or maybe less verbose) way of writing Arr::add

Thursday, August 5, 2021
 
dannyhobby
answered 3 Months ago
94

PHPWord is on Packagist, so installing it on Laravel is as easy as:

composer require phpoffice/phpword

or adding this to your composer.json then running composer install:

"require": {
   "phpoffice/phpword": "dev-master"
}

Once installed, you can use it in your code like this (taken from the documentation):

// Creating the new document...
$phpWord = new PhpOfficePhpWordPhpWord();

/* Note: any element you append to a document must reside inside of a Section. */

 // Adding an empty Section to the document...
$section = $phpWord->addSection();

// Adding Text element to the Section having font styled by default...
$section->addText(
    htmlspecialchars(
        '"Learn from yesterday, live for today, hope for tomorrow. '
            . 'The important thing is not to stop questioning." '
            . '(Albert Einstein)'
    )
);

// Saving the document as HTML file...
$objWriter = PhpOfficePhpWordIOFactory::createWriter($phpWord, 'HTML');
$objWriter->save('helloWorld.html');
Tuesday, August 10, 2021
 
daiscog
answered 2 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :