mardi 25 avril 2017

How to check another table's columns and get their values to the other table

i am struggling over this problem Shortly, i have payments page. Admin selects the user and course, then he should select course_type,which gets value from courses table's three columns(cost_group, cost_minigroup, cost_individual,one of them). If course_type is selected, the cost of course must be inserted into payments table(inside course_cost column). So what i have done

Tables:

payments{
          id,
          student_id, 
          course_id, 
          course_cost}
courses {
          id, 
          name, 
          cost_group, 
          cost_minigroup, 
          cost_individual }

My CourseController.php

>  public function get($id) {
>         $course = Course::findOrFail($id);
> 
>         return response()->json($course);
>     }

Here is my form.blade.php

<div class="field">    
   <div class="ui selection dropdown">    
   <input type="hidden" name="course_">
    <i class="dropdown icon"></i>
     <div class="default text">Course type</div>
      <div class="menu">
       <div class="item" data-value="course_group">Group</div>                  
       <div class="item" data-value="course_minigroup">Mini Group</div>
       <div class="item" data-value="individual">Individual</div>
                         </div>
                     </div>
                 </div>

My PaymentsController

 public function store() {
      $payment = new Payment;
      $payment->student_id = Input::get('student_id');
      $payment->course_id = Input::get('course_id');
      $payment->course_cost = Input::get('cost');
      $payment->save();

        return redirect('payment');
        }

so here is problem how to get this cost value in paymentscontroller. If you know how to solve or any method or advice would be great. Thank you in advance guys.



via Chebli Mohamed

lundi 24 avril 2017

laravel test issue-> for index controller function

how be the unit test format for this type of code in laravel ? this is belong to function index in controller

$data = Data
      ::where('client_id', $this->client->id)
        ->paginate(10);

how i can do test for this part of code ?

i did this

// public function testIndex()
// {     

// $response = $this->call('GET', '/backend/route-data'); // $this->assertEquals(302, $response->status());

// }

but i dont know how to do upper code



via Chebli Mohamed

Error: Call to undefined method Illuminate\Http\Response::assertViewHas()

i have this test for create function of controller

public function createTest()
{   
    $user = factory(App\User::class)->create([
        'email' => 'testuser@arabiaweather.com',
        'password' => bcrypt($this->password),
        'type' => 'admin'
    ]);
    $this->be($user);
    $response = $this->call('GET', '/client/1/profile/2/data');
    var_dump($response);

    $response->assertViewHas('client', 1); 
    $response->assertViewHas('clientProfile', 2);

    $this->visit('/client/1/profile/2/data/create')

    ->seePageIs('/client/1/profile/2/data/create');
     $this->user->delete();

}

I got this error

 Error: Call to undefined method Illuminate\Http\Response::assertViewHas()

how i can solve it?



via Chebli Mohamed

InvalidArgumentException: Unable to locate factory with name [default] [App\Routedata]

This is my function

public function create($alias, $profileId)
    {
        $this->setClientAndClientProfile($alias, $profileId);

        return view('client.data.map')->with('client', $this->client)->with('clientProfile', $this->clientProfile);
    }

and this is test that i write it

public function createTest()
    {
        $this->Data = factory(App\Data::class)->create([
            'id' => '1',
            'client' => 'first',
            ' name' => 'name1',
            'Status' => ''

        ]);
       $this->be($this->$RouteForecast);
       $this->visit('/backend/data')

        ->seePageIs('/backend/data');

    }

when i run i got this error

InvalidArgumentException: Unable to locate factory with name [default] [App\Data].

how i can solve this problem ?



via Chebli Mohamed

dimanche 23 avril 2017

laravel index method test The response was not a view. Failed asserting that false is true

this is my test function for index function

/** @test */

public function testIndex()
{
    $this->call('GET', '/backend/route-data');

    $this->assertViewHas('routedata');
    $this->assertViewHas('client');
    $this->assertViewHas('clientProfile');

    $routedata = $response->original->getData()['routeData'];
    $client = $response->original->getData()['client'];
    $clientProfile = $response->original->getData()['clientProfile'];

    $this->assertInstanceOf('\Illuminate\Database\Eloquent\Collection', $routeData);
    $this->assertInstanceOf('\App\Client', $client);
    $this->assertInstanceOf('\App\ClientProfile', $clientProfile);

}

this is the index function

public function index($alias, $profileId) { $this->setClientAndClientProfile($alias, $profileId);

$routeData = RouteData
                    ::where('client_id', $this->client->id)
                    ->paginate(10);

return view('client.route_data.index', compact('routeData'))->with('client', $this->client)->with('clientProfile', $this->clientProfile);

}

I got this error RouteIndex::testIndex The response was not a view. Failed asserting that false is true. how I can fix this :)



via Chebli Mohamed

laravel unit test index function in controlller

this is my index function

public function index($alias, $profileId)
{
    $this->setClientAndClientProfile($alias, $profileId);

    $routeData = Routedata
                        ::where('client_id', $this->client->id)
                        ->paginate(10);

    return view('client.route_data.index', compact('routedata'))->with('client', $this->client)->with('clientProfile', $this->clientProfile);
}

setClientAndClientProfile is function just to check type of user and bring his profile

so how to write a test for this function?



via Chebli Mohamed

jeudi 20 avril 2017

laravel , error not find in migrate:rollback

in laravel 5.1 , vagrant, when I run

php artisan migrate 

Migrated: 2017_04_20_205912_alter_3_discounts_table

but when I run

php artisan migrate:rollback

show this message :

[Symfony\Component\Debug\Exception\FatalThrowableError]
  Class 'Alter3DiscountsTable' not found

I Have this class but I don't know why show this message!

any body can help?

** I run composer dumpautoload and show this :

[RuntimeException]                                                                                                                                               
File at "/vendor/phpunit/php-code-coverage/src/CodeCoverage/Report/Node/Directory.php" does not exist, check your classmap definitions



via Chebli Mohamed