vendredi 29 janvier 2016

Laravel php's date_add function don't work

Made this Laravel seeder function. Problem is the dates dosen't change as expected. If I run the code in Tinker it works.

What am I doing wrong?

public function run() {
    $faker = Faker::create();

    foreach(range(1, 10) as $index)
    {
        $myDateCalled = $faker->dateTime($max = 'now');

        $myDateAllocated = $myDateCalled;
        $i = $faker->numberBetween($min = 5, $max = 300);
        date_add($myDateAllocated, date_interval_create_from_date_string("{$i} seconds"));

        $myDatePickedUp = $myDateAllocated;
        $i = $faker->numberBetween($min = 5, $max = 30);
        date_add($myDatePickedUp, date_interval_create_from_date_string("{$i} minutes"));

        $myDateDelivered = $myDatePickedUp;
        $i = $faker->numberBetween($min = 10, $max = 90);
        date_add($myDateDelivered, date_interval_create_from_date_string("{$i} minutes"));


        dd($myDateCalled, $myDateAllocated, $myDatePickedUp, $myDateDelivered);

        Hhtransport::create([
            'Called' => $myDateCalled,
            'Allocated' => $myDateAllocated,
            'PickedUp' => $myDatePickedUp,
            'Delivered' => $myDateDelivered,
            'From' => $faker->numberBetween($min = 1, $max = 99),
            'To' => $faker->numberBetween($min = 1, $max = 99),
            'Put' => $faker->numberBetween($min = 1, $max = 99),
            'Drev' => $faker->numberBetween($min = 1, $max = 99),
            'Container' => $faker->numberBetween($min = 1, $max = 99)
        ]);
    }
}



via Chebli Mohamed

create image thumbnails i laravel 5.0

**how to create image thumbnails i use different library but thumbnail not create **

 public function store(Request $request){
     $user_id = \Auth::user()->id;
    $image = new Image();
    $this->validate($request, [
        'title' => 'required',
        'description' => 'required',
        'image' => 'required'
    ]);
    $image->title = $request->title;
    $image->description = $request->description;
    $image->user_id = $user_id;
    if($request->hasFile('image')) {
        $file = Input::file('image');
        //getting timestamp
        $timestamp = str_replace([' ', ':'], '-', Carbon::now()->toDateTimeString());
      $name = $timestamp. '-' .$file->getClientOriginalName();
         $image->filePath = $name;
      $file->move(public_path().'/images/', $name);
  }
    $image->save();
     return $this->upload()->with('success', 'Image Uploaded Successfully');
}

** **how to create image thumbnails i use different library but thumbnail not create ****



via Chebli Mohamed

laravel 5 pagination issue 5

I'm trying to build a website with laravel and I'm using pagination to show the result of searching. when I click on search button , it works but when I click on the next page of the pagination ,all values ​​of search form disappear and there is no result in searching is there anyone to help؟

route.php

Route::get('search', 'searchController@index');//return search view
Route::post('misearch', 'searchController@search');// return result 
Route::resource('misearch', 'searchController@search');// for pagination

searchController.php

$results =  Mod_ads::where(function($query){
$ins_brand = Input::has('ins_brand')? Input::get('ins_brand'):null;
$min_price = Input::has('min_price')? Input::get('min_price'):null;
$max_price = Input::has('max_price')? Input::get('max_price'):null;
$ins_color = Input::has('ins_color')? Input::get('ins_color'):null;


if (isset($min_price) && isset($max_price)) {
    $query -> where('ads_fie_insprice', '>=', $min_price)->
        where('ads_fie_insprice', '<=', $max_price);
    }


    if ($ins_brand == '0') {
        unset($ins_brand);
    }else{
        $query->where('ads_fie_insbrand', '=', $ins_brand);
    }


    if (isset($ins_color)) {
        $query->where('ads_fie_inscolor', 'LIKE', '%'.$ins_color.'%');
    }


        })->paginate(2);
        $link = str_replace('/?', '?', $results->render());
        return View::make('search', compact('results', 'link'));

search.blade.php

@if(isset($results))
  @foreach($results->getCollection()->all() as $result) 
      {{ $result->ads_fie_insbrand }}
      {{ $result->ads_fie_insprice }}
      {{ $result->ads_fie_inscolor }}
  @endforeach 
@endif 

                @if(isset($results))
                 {!! $link !!} 
                @endif



via Chebli Mohamed

Laravel container doesn't resolve Test methods dependencies

I have a test suit for a CLI program created in App\Commands namespace. The problem I have is that it seems laravel container doesn't resolve test method dependencies nor laravel helpers, ... . I'm on Windows 10.

PHP code :

<?php

use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;

use ACME\SomeClass;

class CLICommandTest extends TestCase
{
    use DatabaseTransactions;

    protected $key = '';
    protected $someClass = null;

    public function __construct(SomeClass $someClass)
    {
        parent::__construct();

        $this->someClass = $someClass;
        $this->key = config('someconfig')['key'];
    }

    /*
     * test handle method
     */
    public function testHandle()
    {
        //assertions
    }

}

I've created & included the service provider for this :

<?php

use ACME\someClass;

$this->app->bind('ACME\SomeClass', function($app){
    return new SomeClass($value);
});

when I run phpunit from either PATH or vendor/bin this error comes up :

PHP Fatal error:  Uncaught TypeError: Argument 1 passed to CLICommandTest::__construct() must be an instance of ACME\someClass, none given, called in phar://C:/PHPUnit/phpunit/phpunit/Framework/TestSuite.php on line 475 and defined in C:\path\tests\CLICommandTest.php:16
Stack trace:
#0 phar://C:/PHPUnit/phpunit/phpunit/Framework/TestSuite.php(475): CLICommandTest->__construct()
#1 phar://C:/PHPUnit/phpunit/phpunit/Framework/TestSuite.php(880): PHPUnit_Framework_TestSuite::createTest(Object(ReflectionClass), 'testHandle')
#2 phar://C:/PHPUnit/phpunit/phpunit/Framework/TestSuite.php(195): PHPUnit_Framework_TestSuite->addTestMethod(Object(ReflectionClass), Object(ReflectionMethod))
#3 phar://C:/PHPUnit/phpunit/phpunit/Framework/TestSuite.php(297): PHPUnit_Framework_TestSuite->__construct(Object(ReflectionClass))
#4 phar://C:/PHPUnit/phpunit/phpunit/Framework/TestSuite.php(381): PHPUnit_Framework_TestSuite->addTestSuite(Object(ReflectionClass))
#5 phar://C:/PHPUnit/phpunit/phpunit/Framework/TestSuit in C:\path\tests\CLICommandTest.php on line 16

Fatal error: Uncaught TypeError: Argument 1 passed to CLICommandTest::__construct() must be an instance of ACME\someClass, none given, called in phar://C:/PHPUnit/phpunit/phpunit/Framework/TestSuite.php on line 475 and defined in C:\path\tests\CLICommandTest.php on line 16

TypeError: Argument 1 passed to CLICommandTest::__construct() must be an instance of ACME\someClass, none given, called in phar://C:/PHPUnit/phpunit/phpunit/Framework/TestSuite.php on line 475 in C:\path\tests\CLICommandTest.php on line 16

Call Stack:
    0.0036     492584   1. {main}() C:\PHPUnit\phpunit:0
    0.1375    8875000   2. PHPUnit_TextUI_Command::main() C:\PHPUnit\phpunit:515
    0.1375    8878160   3. PHPUnit_TextUI_Command->run() phar://C:/PHPUnit/phpunit/phpunit/TextUI/Command.php:106
    0.1375    8878160   4. PHPUnit_TextUI_Command->handleArguments() phar://C:/PHPUnit/phpunit/phpunit/TextUI/Command.php:117
    0.1624   10379328   5. PHPUnit_Util_Configuration->getTestSuiteConfiguration() phar://C:/PHPUnit/phpunit/phpunit/TextUI/Command.php:663
    0.1624   10379912   6. PHPUnit_Util_Configuration->getTestSuite() phar://C:/PHPUnit/phpunit/phpunit/Util/Configuration.php:796
    0.1651   10381496   7. PHPUnit_Framework_TestSuite->addTestFiles() phar://C:/PHPUnit/phpunit/phpunit/Util/Configuration.php:885
    0.1651   10381496   8. PHPUnit_Framework_TestSuite->addTestFile() phar://C:/PHPUnit/phpunit/phpunit/Framework/TestSuite.php:409
    0.1732   10916648   9. PHPUnit_Framework_TestSuite->addTestSuite() phar://C:/PHPUnit/phpunit/phpunit/Framework/TestSuite.php:381
    0.1732   10917104  10. PHPUnit_Framework_TestSuite->__construct() phar://C:/PHPUnit/phpunit/phpunit/Framework/TestSuite.php:297
    0.1733   10982344  11. PHPUnit_Framework_TestSuite->addTestMethod() phar://C:/PHPUnit/phpunit/phpunit/Framework/TestSuite.php:195
    0.1733   10982760  12. PHPUnit_Framework_TestSuite::createTest() phar://C:/PHPUnit/phpunit/phpunit/Framework/TestSuite.php:880
    0.1735   10986272  13. CLICommandTest->__construct() phar://C:/PHPUnit/phpunit/phpunit/Framework/TestSuite.php:475

Whats the problem?



via Chebli Mohamed

Can I get a value localized by javascript in blade template?

In html, I can get a value localized by below code:

{{Lang::get('frontend/error_message.EMAIL_BLANK')}}

I want to use javascript to check valid input data, and get value from localized, but it not working with below code:

error = <?php echo \Lang::get('frontend/error_message.EMAIL_BLANK');?>
error = <?php echo Lang::get('frontend/error_message.EMAIL_BLANK');?>
error = {{Lang::get('frontend/error_message.EMAIL_BLANK')}}



via Chebli Mohamed

Global search in website using php & mysql

I want to implement search option in page header. Results will contain all records those contain filter text.e.g. products. What is the best way to implement global search in website.



via Chebli Mohamed

jeudi 28 janvier 2016

Laravel $push->getAdapter()->getResponse() is blank for iphone

I am using Laravel push notification library, for pushing notification. However, i can easly get responses for GCM responses for Android Device. But unable to get APNS response.

$message = PushNotification::Message("New Messages",$params['payload']);
        $collection = PushNotification::app('appNameIOS')
                ->to($params['reg_id'])
                ->send($message);
    foreach ($collection->pushManager as $push) {
        $response = $push->getAdapter()->getResponse();
    }



via Chebli Mohamed