vendredi 1 janvier 2016

Modify the value for laravel 5.1 form input with javascript

I have it working with java script and html but when i use laravel forms it wont work

java script

  document.getElementById('user-image').setAttribute('value', res.path);

html:

<input  id="user-image" value="">

with laravel form then i cant seem to get it to change the value

{!! Form::hidden('user-image', '', array('id' => 'user-image')) !!}



via Chebli Mohamed

How to solve Unable to locate factory with name [default] [App\Models\Domain]?

I'm trying to add a Factory to help increment my test coverage on some controllers. I've been using Factories with no issues till now, where I find no reason for this message and I can't figure out what is different from the rest of the factories, which are working perfectly.

The error is:

1) GuestBusinessControllerTest::it_presents_a_domain_home
InvalidArgumentException: Unable to locate factory with name [default] [App\Models\Domain].

In order not to make a never-ending post of code crap, I reference the useful files as follows:

Sidenotes:

Yes, I did composer dump-autoload (Else, the error message would be different)

I tried to define the factory in another helper file, and dump-autoload. (Just in case)

I also tried renaming my model, thinking that Domain might be a conflicting keyword, but that seems not to be the issue.

How may I solve this error?



via Chebli Mohamed

Get all Permission Role Names for a specific RoleId in Laravel Entrust

In Laravel Entrust, I need to get all the linked permissions of a specific roleId. How can I do that? I see the permission_role table has the roleId and permissionId relation and then the permissions table has the permission data. Say, if I want to get all permissions for the roleId: 2, how can I do that?

What I found:

I understand, I can use the with(perms) like below but it fetches the list of all roles with permissions which I don’t want.

$roles = Role::with('perms')->get();

What I want: Fetch the permission list of a particular roleId that outputs in an array like this:

(
            [create-article] => true
            [edit-article] => true
            [edit-article] => true
 )

Where the permission_name is set as key and true set as value since I then use the above array in frontend javascript for checks.



via Chebli Mohamed

Routing categories, subcategories and articles with Laravel

I often see websites that have pretty URLs for categories, subcategories and articles. How do I replicate this function with Laravel?

I need to get the following routes working:

/kb/{id (numeric)}
/kb/{category}
/kb/{category}/{article} (redirects to the route immediately below, adding the id)
/kb/{category}/{article}/{id (numeric)}
/kb/{category}/{subcategory}
/kb/{category}/{subcategory}/{article} (redirects to the route immediately below, adding the id)
/kb/{category}/{subcategory}/{article}/{id (numeric)}
/kb/download/{id (numeric)}

I was also going to try and include pretty URLs for pagination, but I realised it might complicate it further to have categories and subcategories have a /page/1 part after - but, if you know how to make that work, please tell!

Currently, my code is as follows:

Route::group(['prefix' => '/kb', 'as' => 'kb::'], function () {

    Route::get('/', function() {
        echo "<h1>Index</h1>";        
    });

    Route::get('{id}', function($id = null) {
        echo "<h1>ID: $id</h1>";
    })->where('id', '0-9+');

    Route::get('download/{id}', function($id = null) {
        echo "<h1>Download ID: $id</h1>";
    })->where('id', '0-9+');

    Route::get('{category}', function($category = null) {
        echo "<h1>Category: $category</h1>";
    });
    Route::get('{category}/{article}', function($category = null, $article = null) {
        echo "<h1>Category: $category</h1>";
        echo "<h1>Article: $article</h1>";
    });
    Route::get('{category}/{article}/{id}', function($category = null, $article = null, $id = null) {
        echo "<h1>Category: $category</h1>";
        echo "<h1>Article: $article</h1>";
        echo "<h1>ID: $id</h1>";
    })->where('id', '0-9+');

    Route::get('{category}/{subcategory}', function($category = null, $subcategory = null) {
        echo "<h1>Category: $category</h1>";
        echo "<h1>SubCategory: $subcategory</h1>";
    });
    Route::get('{category}/{subcategory}/{article}', function($category = null, $subcategory = null, $article = null) {
        echo "<h1>Category: $category</h1>";
        echo "<h1>SubCategory: $subcategory</h1>";
        echo "<h1>Article: $article</h1>";
    });
    Route::get('{category}/{subcategory}/{article}/{id}', function($category = null, $subcategory = null, $article = null, $id = null) {
        echo "<h1>Category: $category</h1>";
        echo "<h1>SubCategory: $subcategory</h1>";
        echo "<h1>Article: $article</h1>";
        echo "<h1>ID: $id</h1>";
    })->where('id', '0-9+');

});

Unfortunately, this has a habit of mixing up articles and subcategories, and is a total mess. But I see websites with this structure, and even more complicated structures, and they work - what's the secret?!

It's also important to remember that two categories might have subcategories with the same name, that aren't the same subcategory, further complicating things.

EDIT: I've also just taken a look at maybe making each article be prefixed with article, like /kb/cat/article/evil/666. Still doesn't seem to work right though, irritatingly.



via Chebli Mohamed

Laravel 5.2 named route usage with variable parameter

Happy new year!

I have a route like this:

// Open New Subscription page
Route::get('/account/subscriptions/create/{menu}', ['uses' => 'Subscriptions\SubscriptionController@create', 'as' => 'subscription.create']);

In my blade template I use the named route like this:

<a href="{!! route('organisations.index') . "/p11-c3" !!}">

But this format does not work.

How do I pass the variable menu a value while still using the named route (rather than hard coding a url in the href)?



via Chebli Mohamed

How to use withoutOverlapping() with everyFiveMinutes() in Laravel Schedule

How i can use withoutOverlapping here?

$schedule->call(function () 
        {
           //Some Code
        })->everyFiveMinutes();



via Chebli Mohamed

jeudi 31 décembre 2015

GroupBy Query Laravel 5.1

I'm having problem in fetching the data using groupBy, I don't where I'm wrong, I have done it many times before, but today I'm wrong some where and I don't know where. Following is the Table from which I want to select the Data:

Table Name: user_questions

id | user_id | message | read_status_user | read_status_support | answered

Now suppose if one user sends more than one messages, then user_id will be repeated, So to want all the message from one particular user I'm firing the query like following:

UserQuestion::groupBy('user_id')->get();

This should give me the result like

user_id = 1 > message1
user_id = 1 > message2
....
user_id = 1 > message...(if any)

user_id = 2 > message1
user_id = 2 > message2
..... 
So on...

But this is always giving me only one message from the particular user. I don't know why. Is there any mistake? I have tried another queries too, but all are giving me the same result.

Please help me with this. Everybody's help will be highly appreciated. Thanks to all of you in advance.



via Chebli Mohamed