mercredi 28 octobre 2015

we failed to identify your request PHPUNIT

I have a test function -

class InstrumentTest extends TestCase {

    private $faker; 

    public function setUp() {
        $this->refreshApplication();
        $this->faker = Faker\Factory::create('en_EN');

        $user = App\User::find(2);

        $this->be($user);
    }

    /**
     * Test creating new instrument
     */
    public function testCreateNewInstrument() {
        $fakeName = $this->faker->name;

        $this->visit('/oem/instrument/create')
                ->type($fakeName, 'name')
                ->press('Create')
                ->seePageIs('/oem/instrument')
                ->see('Instrument Created Successfully!');

        # make sure that record is in the database
        $this->seeInDatabase('instrument', ['name' => $fakeName, 'company_id' => 1]);
    }
}

Each time I run "phpunit" my test die with following message in the console: "We failed to identify your request."

I am not sure on how to fix this and if this is related to the middleware?



via Chebli Mohamed

grant permission to a new role in Laravel 5

We are developing a laravel application, the application has an admin part which is only accessible to the admin users in routes file we have:

 Route::group(['middleware' => 'admin', 'prefix' => 'admin', 'namespace'
              => 'Admin'] , function() {
       Route::get('oldAdminUrl', 'oldControllwe@handle');

  }

The middleware file's handle function is like

public function handle($request, Closure $next)
{       
   if ($this->admin->guest())
    {
        //some code here
    }

    return $next($request);
}

ad the $this->Admin refers to Model called adminModel with the following attribute

 protected $table = 'admin'

Now we need to add a new url to the group of admin urls let's call it newAdminUrl it should be accessabile for both the admin users and also a new group of users let's call them editors

is it a good practice to put that url outside the admin group and assign it a new middleware let's call it editorsMiddleware in additon to admin middleware to check if the user who wants to access the newAdminUrl is either in editor group or admin group and the editors be stored in another table

 Route::group(['middleware' => ['admin','editors], 'prefix' => 'admin',      
     'namespace' => 'Admin'] , function() {
         Route::get('newAdminUrl', 'newControllwe@handle');

   }

The EditorModel which is used inside the editorMiddleware has this attribute:

     protected $table = 'editor'

The Question: what is the right or even good approach to implement it? or anyone has any better idea or suggestion?



via Chebli Mohamed

Laravel 5.1 - Javascript not loaded

My app gets the views from an ajax request by navigation. So when i click a link in my menu i retrieve all the Html that my view contains.

My javascript is included inside the main template and of course all my calls works. But once i need for example to create an animated filter gallery inside a specific view, the javascript for that view doesn't work.

This is how i've organized my app:

My template

<!-- !Doctype -->
@include('partials.doctype')

<!-- Menu -->
@include('partials.menu')

<!-- Cont -->
<section id="content-wrapper">
    @include('ajax.index')
</section>

<!-- Footer -->
@include('partials.footer')

<!-- Javascript -->
@include('partials.javascript')

</body>
</html>

My Controller (if there's an ajax call i retrieve the view without @extends() and @section(), otherwise i retrieve my full view):

// load page
public function loadPage($page){
    return (\Request::ajax()) ? view('ajax.'.$page)->render() : view('pages.'.$page);
}

My views:

For my purpose i've created 2 type of views, one extended and one with only the html i need from my ajax calls.

a) extended, it's inside "pages" folder:

@extends('main')
@section('cont')

@include('ajax.shop')

@stop

b) only html, for ajax calls, inside "ajax" folder:

<div class="content">
    <div class="container-fluid">
        <div class="row page-title-box">
            <h3 class="page-number">N. 67</h3>
            <h1 class="page-title">Shop</h1>
        </div>
    </div>
</div>

I don't understand where to put my javascript for this view if i need to implement an animated filter gallery. I've tried to put javascript inside the view but my app crashed.



via Chebli Mohamed

PHP Imap - Character not allowed in mailbox name: '.'

I try to move an email from Drafts to Sent directory.

I use the imap_mail_move method :

imap_mail_move($imapStream, $mailId, $mailBox, CP_UID);

$imapStream is the imap stream of Drafts directory

$mailBox = {imapserver}Sent

The imap_mail_move method return false

and imap_errors() return :

array:2 [
   0 => "Character not allowed in mailbox name: '.'"
   1 => "Character not allowed in mailbox name: '.'"
]

imap_list() method return :

array:41 [
   28 => "{imapserver}Sent"
   ...
   31 => "{imapserver}Drafts"
   ....
   40 => "{imapserver}INBOX"
]

Anyone has a solution ?



via Chebli Mohamed

Building a REST API in Laravel

I'm going from no-framework development to my first contact with Laravel (using version 5.1) and I'm a bit overwhelmed with the amount of stuffs to handle (migrations, seeds, hateoas, transformers, unit testing, error handling, etc).

I'd like to get some help at the return of the show method portion of it (following REST concepts). I have the following database structure:

companies -> users -> tickets -> interactions -> attachments

enter image description here

Now, when listing a specific ticket (like GET /customers/5/tickets/3), the screen needs to show all interactions for that ticket, along with all information in the ticket table (sort of like a page header) and the name of each user that created the specific interaction.

Thinking in terms of relationship, should I return all that data from the single call or should the information from the tickets table, for instance, be persisted in the front-end (from the index method call)? Even if I should persist the ticket information (header of the page), I am still left with interaction join users + N attachments for each interaction. What are the options to approach this?

I decided to open this thread because I was trying to Unit Test this call and I couldn't decide whether I should seed the database to have all the information necessary for it to work.



via Chebli Mohamed

Inserting millions of records from local to godaddy hosting

I'm trying to insert about 8 million records from an access database to a mysql database in GoDaddy.

I built a desktop java app to manage the inserts chunking 5000 records each time. I use Laravel 5.1 to manage the inserts in the server. So, basically, the java app send a request to a laravel php route, then it take care of inserting directly in my MySQL database. The first part of records inserts successfully, but than when I send another request, I get this error:

2015-10-28 10:43:57.844 java[3475:280209] Communications error: <OS_xpc_error: <error: 0x7fff7298bb90> { count = 1, contents =
    "XPCErrorDescription" => <string: 0x7fff7298bf40> { length = 22, contents = "Connection interrupted" }
}>
Got xpc error message: Connection interrupted
org.apache.http.NoHttpResponseException: api.kraftheinzapp.com:80 failed to respond



via Chebli Mohamed

Class not found error shown after every php artisan run after removing a package

Today after removing spatie/laravel-glide package via composer , after any php artisan running show bellow error message :

  [Symfony\Component\Debug\Exception\FatalErrorException]
  Class 'Spatie\Glide\GlideServiceProvider' not found

I search about this problem and call bellow statment Many times:

composer dump-auto

But the error continues to be displayed.
this is my Composer file:

{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
    "php": ">=5.5.9",
    "laravel/framework": "5.1.*",
    "mews/captcha": "^2.1"
},
"require-dev": {
    "fzaninotto/faker": "~1.4",
    "mockery/mockery": "0.9.*",
    "phpunit/phpunit": "~4.0",
    "phpspec/phpspec": "~2.1"
},
"autoload": {
    "classmap": [
        "database"
    ],
    "psr-4": {
        "App\\": "app/"
    }
},
"autoload-dev": {
    "classmap": [
        "tests/TestCase.php"
    ]
},
"scripts": {
    "post-install-cmd": [
        "php artisan clear-compiled",
        "php artisan optimize"
    ],
    "pre-update-cmd": [
        "php artisan clear-compiled"
    ],
    "post-update-cmd": [
        "php artisan optimize"
    ],
    "post-root-package-install": [
        "php -r \"copy('.env.example', '.env');\""
    ],
    "post-create-project-cmd": [
        "php artisan key:generate"
    ]
},
"config": {
    "preferred-install": "dist"
}

}

What to do?



via Chebli Mohamed