mercredi 31 janvier 2018

Laravel Route URI: Add or condition

I have written a route with uri, which accepts /app/12/password

Route::get('app/{id}/password', 'AppController@pwd')->name('apwd');

Now i want to extend it to also accept /app/12/pwd. What is standard way to do this, since i can't write different route. I tried.

Route::get('app/{id}/(pwd|password)', 'AppController@pwd')->name('apwd');

Any help is appreciated.



via Chebli Mohamed

mardi 30 janvier 2018

Laravel 5.1 Snappy problems with Authentication

I am using Barrydvh\Snappy for PDF generation on my Laravel 5.1 application. The PDF must be generated once the user has logged in, as that view must be kept private.

It seems that the shell opened by wkhtmltopdf creates a parallel session, therefore there is no user authenticated, and I get back the login route instead of the desired private view.

Does anyone know how to handle this?

Thank you all in advance.

Best regards, Marta



via Chebli Mohamed

Laravel 5.1 application setup with existing source code

Am trying to setup laravel application, but it is displaying only laravel default page. not able to run the application.
i have followed below steps. 1)dump the code in xamp\htdocs\sample(application folder name) and updated db details in command prompt 2) composer update 3)php artisan up 4)php artisan serve

after serve command it is displaying as "Laravel development server started on http://localhost:8000/

[Tue Jan 30 14:58:23 2018] ::1:51377 [200]: /favicon.ico
[Tue Jan 30 14:58:26 2018] ::1:51380 [200]: /favicon.ico
[Tue Jan 30 14:59:51 2018] ::1:51384 [200]: /favicon.ico

in browser http://localhost:8000/ displaying laravel defaule page. please let me know how to setup the application and if i miss anything in above steps. thanks in advance.



via Chebli Mohamed

dimanche 28 janvier 2018

Laravel view don't update after adjusting time

I am creating password expiration (90 days) in laravel, then I adjust my current date and put it to 90 days (when changing view its still updating), after test I back my current date and update some view but view is not updating anymore. My Procedure:

Step 1: Go to your laravel project

Step 2: change computer time (ex: if 1/29/2018 now, change it to 7/29/2018)

Step 3: edit your laravel project, check if your view is updating (if yes proceed to step 4 )

Step 4: back your current date, then update your code in view again, its not updating anymore

I am using IIS as my server, laravel 5.1, php 5.5.

I already try to use this.

composer dump_autoload

composer clear-cache

php artisan clear-compiled

php artisan config:clear

php artisan cache:clear

I also try to clear browsing data

Sorry for but English its not my major language.

Thanks a lot.



via Chebli Mohamed

vendredi 26 janvier 2018

BadMethodExcption in Laravel Controller

I created a controller in Laravel but when I call a method from Controller it shows the following error

BadMethodCallException
Method [Register] does not exist on [App\Http\Controllers\UserController].

Thanks,

Aisha Zafar



via Chebli Mohamed

mercredi 24 janvier 2018

Sphinx indexer does not fetch data when MySQL transaction is used

please help me with running phpunit tests that check module with sphinx search engine.

To search in that module I use two sphinx indexes docs and docsdelta. After new data are appear in the DB, I do following:

exec("indexer docsdelta --rotate");
exec("indexer --merge docs docsdelta --rotate");

It works well on my website and I am able to add new document through the web interface and it appears in the search.

On the same time when I run phpunit test and it creates new document "on fly",

exec("indexer docsdelta --rotate");

does not fetch any new data. My phpunit tests use transactions to rollback the database to the previous state and I notice, that indexer works properly in case if I switch off transactions. Additionally I am able to see new data in the DB, just before and after running indexer. Maybe I missed something but I do not understand why transaction has an influence on indexer.

Is it some way to use indexer docdelta together with MySQL transaction?

Thank you in advance for help!



via Chebli Mohamed

jeudi 18 janvier 2018

With chrisbjr/api-guard how do I turn off it auth for a subset of routes

Under Laravel 5.1

How do I turn off api-guard for certain routes and turn it on for others. We're building an app that needs REST API as well as standard web stuff.

We'd like mobile users to be able to log in and get their auth key, then use that for subsequent auth'd calls. Non mobile users to utilize the Laravel auth that comes out of the box.



via Chebli Mohamed

mardi 16 janvier 2018

Send Mail not working in Laravel 5.1

I have created one demo for sending mail. I am sending mail in contact page it is working. But When I use dynamic email for TO, then it is not working.

Not Working

Mail::send('emails.otp_mail_format',['otp'=>'123456'], function($message){ $message->from('no-reply@example.com'); $message->to($uEmailAddress)->subject('Account Verification'); });

But Working below code

Mail::send('emails.otp_mail_format',['otp'=>'123456'], function($message){ $message->from('no-reply@example.com'); $message->to('kanu@example.come')->subject('Account Verification'); });



via Chebli Mohamed

vendredi 12 janvier 2018

Multidimensional Array Laravel

I'm new to laravel and I'm trying to loop through this multidimensional array in the view of blade template but unable to get the elements. I tried using nested foreach but that doesn't work. I'm unsure what else to do. Please help

Array
(
[2] => Illuminate\Support\Collection Object
    (
        [items:protected] => Array
            (
            )

    )

[3] => Illuminate\Support\Collection Object
    (
        [items:protected] => Array
            (
                [0] => stdClass Object
                    (
                        [ActivityID] => 1
                        [WaiverID] => 3
                        [ProgramID] => 1
                        [ActivityName] => Waiver3 Activity 1
                        [WaiverName] => Waiver 3
                        [ID] => 3
                        [WaiverDescription] => 
                        [ProgramID] => 1
                    )

                [1] => stdClass Object
                    (
                        [ActivityID] => 2
                        [WaiverID] => 3
                        [ProgramID] => 1
                        [ActivityName] => Waiver3 Activity 2
                        [WaiverName] => Waiver 3
                        [ID] => 3
                        [WaiverDescription] => 
                        [ProgramID] => 1
                    )

                [2] => stdClass Object
                    (
                        [ActivityID] => 3
                        [WaiverID] => 3
                        [ProgramID] => 1
                        [ActivityName] => Waiver3 Activity 3
                        [WaiverName] => Waiver 3
                        [ID] => 3
                        [WaiverDescription] => 
                        [ProgramID] => 1
                    )

            )

    )

)

When I do a foreach like this

@foreach ($waiverActivityforTable as$waiverActivityforTableValue)           
    
@endforeach

I get:

[] [] [{"ActivityID":1,"WaiverID":3,"PHAProgramID":1,"ActivityName":"Waiver3 
Activity 1","HCVWaiverName":"Waiver 
3","ID":3,"HCVWaiverDescription":null,"phaProgramID":1},
{"ActivityID":2,"WaiverID":3,"PHAProgramID":1,"ActivityName":"Waiver3 
Activity 2","HCVWaiverName":"Waiver 
3","ID":3,"HCVWaiverDescription":null,"phaProgramID":1},
{"ActivityID":3,"WaiverID":3,"PHAProgramID":1,"ActivityName":"Waiver3 
Activity 3","HCVWaiverName":"Waiver 
3","ID":3,"HCVWaiverDescription":null,"phaProgramID":1}] 

Tired nested foreach: I tried:

    @foreach ($waiverActivityforTable as $waiverActivityforTableValue)
        @foreach ($waiverActivityforTableValue as $test)
            
        @endforeach
    @endforeach

but I get an error: htmlspecialchars() expects parameter 1 to be string, object given



via Chebli Mohamed

jeudi 11 janvier 2018

Queuing mail with attachData in Laravel 5.1 / OctoberCMS

The following IS working when I use Mail::send

$email = 'my@email.com';
$name = 'My Name';
$invoice = InvoicePdf::generate($invoice_id); // generates PDF as raw data

Mail::send('mail.template', null, function($message) use ($name, $email, $invoice) {

    $message->to($email, $name);
    $message->subject('Thank you for your order!');
    $message->attachData($invoicePdf, 'invoice.pdf', ['mime' => 'application/pdf']);

});

It works fine and an email is generated with the correct PDF attachment.

However, if I change Mail::send to Mail::queue then I receive the following error:

Unable to JSON encode payload. Error code: 5

/var/www/html/october/vendor/laravel/framework/src/Illuminate/Queue/Queue.php line 90

If I take the $message->attachData(); line out then it works even with Mail::queue so it seems like the raw data from the attachment is causing issues with the queue but there's nothing in the relevant October or Laravel docs about how to deal with this.



via Chebli Mohamed

mercredi 10 janvier 2018

Auth login issue with different table name and different field

I have user table. That name is tb_users. The field is user_name, user_email, user_pwd, remember_token etc.

I have changed in auth.php

  protected $table = 'mb_uzer181006';

  protected $fillable = ['user_name', 'user_email', 'user_pwd'];

  protected $hidden = ['user_pwd', 'remember_token'];

ErrorException in EloquentUserProvider.php line 112:

Undefined index: password

I am not sure how I will solve this problem. I want to learn auth login with a different field name not same same Users table



via Chebli Mohamed

mardi 9 janvier 2018

Datagrid - both condition branches fire

I have a following code:

public function index(ArticleRepository $articleRepository)
    {
        $this->authorize($this->prefix());
        $filterCategory = Request::get('category');

        if (!Request::ajax()) {
            // Then just return main index admin template, that will ajax-load the data
            return View::make($this->prefix('index'))
                ->with("dataSource", URL::route($this->prefix('index')));
        } else {
            // We'll use DataGrid to display admin listing, first define some basic settings
            $columns = array(
                'id',
                'title',
                'slug',
                'published',
                'translations',
                'cities',
                'faqs',
                'articleCategories',
            );
            $settings = array(
                'sort' => 'id',
                'direction' => 'asc',
                'max_results' => 20
            );

            $commonHandler = $this->articleRepo->filteredData($filterCategory);
            // And finally return DataGrid instance, that will handle all
            return DataGrid::make($commonHandler, $columns, $settings);
        }
    }

The thing that I am curious about is that the both - if and also the else part of code is fired. I guess there are maybe some redirect or something. I am not sure how the datagrid works but when I put the dd(Request::get('category')) to the if(!Request::ajax()) branch I get the data from the Url I am expecting but when I put that code to the else branch I get null. My question is why the both branches fire and if it is caused just by some redirect how do I pass these data (Reqest::get('category')) to the else branch.



via Chebli Mohamed

jeudi 4 janvier 2018

Laravel 5.1 output AuthMiddleware Serverfireteam

BadMethodCallException in Macroable.php line 81: Method aliasMiddleware does not exist.

in Macroable.php line 81
at Router->__call('aliasMiddleware', array('PanelAuth', 'Serverfireteam\Panel\libs\AuthMiddleware')) in PanelServiceProvider.php line 36
at Router->aliasMiddleware('PanelAuth', 'Serverfireteam\Panel\libs\AuthMiddleware') in PanelServiceProvider.php line 36
at PanelServiceProvider->register() in Application.php line 531
at Application->register(object(PanelServiceProvider)) in ProviderRepository.php line 74
at ProviderRepository->load(array('Illuminate\Foundation\Providers\ArtisanServiceProvider', 'Illuminate\Auth\AuthServiceProvider', 'Illuminate\Broadcasting\BroadcastServiceProvider', 'Illuminate\Bus\BusServiceProvider', 'Illuminate\Cache\CacheServiceProvider', 'Illuminate\Foundation\Providers\ConsoleSupportServiceProvider', 'Illuminate\Routing\ControllerServiceProvider', 'Illuminate\Cookie\CookieServiceProvider', 'Illuminate\Database\DatabaseServiceProvider', 'Illuminate\Encryption\EncryptionServiceProvider', 'Illuminate\Filesystem\FilesystemServiceProvider', 'Illuminate\Foundation\Providers\FoundationServiceProvider', 'Illuminate\Hashing\HashServiceProvider', 'Illuminate\Mail\MailServiceProvider', 'Illuminate\Pagination\PaginationServiceProvider', 'Illuminate\Pipeline\PipelineServiceProvider', 'Illuminate\Queue\QueueServiceProvider', 'Illuminate\Redis\RedisServiceProvider', 'Illuminate\Auth\Passwords\PasswordResetServiceProvider', 'Illuminate\Session\SessionServiceProvider', 'Illuminate\Translation\TranslationServiceProvider', 'Illuminate\Validation\ValidationServiceProvider', 'Illuminate\View\ViewServiceProvider', 'Intervention\Image\ImageServiceProvider', 'Collective\Html\HtmlServiceProvider', 'Barryvdh\Debugbar\ServiceProvider', 'Baum\Providers\BaumServiceProvider', 'Barryvdh\TranslationManager\ManagerServiceProvider', 'Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider', 'Greggilbert\Recaptcha\RecaptchaServiceProvider', 'Serverfireteam\Panel\PanelServiceProvider', 'pulsar\Providers\AppServiceProvider', 'pulsar\Providers\HelperServiceProvider', 'pulsar\Providers\AuthServiceProvider', 'pulsar\Providers\EventServiceProvider', 'pulsar\Providers\RouteServiceProvider')) in Application.php line 507
at Application->registerConfiguredProviders() in RegisterProviders.php line 17
at RegisterProviders->bootstrap(object(Application)) in Application.php line 203
at Application->bootstrapWith(array('Illuminate\Foundation\Bootstrap\DetectEnvironment', 'Illuminate\Foundation\Bootstrap\LoadConfiguration', 'Illuminate\Foundation\Bootstrap\ConfigureLogging', 'Illuminate\Foundation\Bootstrap\HandleExceptions', 'Illuminate\Foundation\Bootstrap\RegisterFacades', 'Illuminate\Foundation\Bootstrap\RegisterProviders', 'Illuminate\Foundation\Bootstrap\BootProviders')) in Kernel.php line 222
at Kernel->bootstrap() in Kernel.php line 117
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 87
at Kernel->handle(object(Request)) in index.php line 54

Routes

<?php

get('/', 'FrontendController@index');

get('/bayi-basvuru-formu', function (){
    return view('frontend.bayi-basvuru-formu');
});

  Route::post('contact_store', 
  ['as' => 'contact_store', 'uses' => 'FrontendController@store']);
include 'adminRoutes.php';



via Chebli Mohamed

mercredi 3 janvier 2018

Laravel web application website url case sensitivity Upper case lower case

I have a web application build in php Laravel Framework version 5.1.19. It is running on plesk server, I am having problem with website url case sensitivity. Before the website was working in lower case url but know it does not work. I have to put the path in uppercase for eg: http://ift.tt/2E01MJV it was working before in this format but now it is not working but when I write http://ift.tt/2EPuSg8 it will work. Note Url used is just for demonstration. What should I do ?



via Chebli Mohamed

mardi 2 janvier 2018

Multi storage paths

I have server with 2 hdd. I want to use one for all media files, which are on storage/app/media for current media files and other for all files before 2018.

How can I switch storage path depends on query I make.

All media are saved on media table. I can make changes on table if needed.



via Chebli Mohamed

Laravel 5.1 How to sort collection using lists() method

I have two questions/help to fix here:

  1. How to reduce redundancy in this line of code $this->all()->lists('name', 'id')->all()
  2. How to call mutator by using orderBy method.

helper.php

if (! function_exists('withEmpty')) {

    function withEmpty($selectList, $emptyLabel = '')
    {
        return array('' => $emptyLabel) + $selectList;
    }
}

Agent.php (model)

public function getNameAttribute($value){
    return $this->lname.', '.$this->fname.' '.$this->mname;
  }

public function listAgents($emptyLabel = '--Select Agent--'){

    return withEmpty($this->all()->lists('name', 'id')->all(), $emptyLabel);


  }



via Chebli Mohamed