Tuesday, May 23, 2017

email validation not working in update form using laravel validation

$id = $request->id;
$validation = Validator::make($request->all(), [
   'email' => 'unique:customers,email,'.$request->id
]);



via suresh

How can I add operator ternary in class on the view laravel blade?

I try like this :

@for($i = 0; $i < 5; $i++) 
...
    <div class="image ($i==0) ? 'image-main' : ''">
...
@endfor

But it does not work.

It seems the way of writing is incorrect.

How can I solve this problem?



via Trending News

Select Query - Upto Previous Date Records is Not Working in Laravel

Following Laravel Query I Write for to get Upto Previous Date Records. thats Not Get any Records. If i Remove Date query its get Many Records. my $data['frmdate_submit'] format is 2017-05-24. How to Fix this Problem

$getpreviousbalance=Companyledger::where('transaction_date','>',$data['frmdate_submit'])->WhereIn('frm_ledger',$ledgerlist)->where('company_id',$companyids)->get();    



via abitha shal

Dependency resolving with make not working when bind is done by a provider in Laravel

I'm using Laravel 5.2. I tried to resolve a dependency in laravel out of the IOCContainer as follows.(with App::make method)

App/FooController.php:-

<?php

namespace App\Http\Controllers;

use App\Bind\FooInterface;
use Illuminate\Support\Facades\App;

class FooController extends Controller
{
    public  function outOfContainer(){
        dd(App::make('\App\bind\FooInterface')); // Focus: program dies here!!
    }
}

Bindings for the FooInterface done in the AppServiceProvider as follows

App/Providers/AppServiceProvider.php:-

<?php

namespace App\Providers;

use App\Bind\Foo;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    public function register()
    {
        $this->app->bind('\App\Bind\FooInterface', function() {
            return new Foo();
        });
    }
}

Structure of the Foo class as follows.

App/Bind/Foo.php:-

<?php

namespace App\Bind;


class Foo implements FooInterface {

} 

Structure of the 'FooInterface' interface as follows:-

<?php

namespace App\Bind;


interface FooInterface {

}

Then I created a routed as follows.

Route::get('/outofcontainer', 'FooController@outOfContainer');

But when I browse this route it throws an exception in informing,

BindingResolutionException in Container.php line 748:
Target [App\bind\FooInterface] is not instantiable.

What is going wrong with this? How to use App:make() with the AppServiceProvider?



via user8057101

Laravel Join multiple table not working

I'm having an issue on Laravel 5.4 when I try to use only one join it works ok and returns correct data, but their add another join it doesn't work.

$data = Player::select(DB::raw('CONCAT(familyName,", ",firstName) AS fullName'))
    ->where('firstname', 'like', '%'.$search.'%')
    ->orWhere('familyName', 'like', '%'.$search.'%')
    ->orderBy('familyName', 'asc')
    ->join('teams', 'players.primaryClubId', '=', 'teams.clubId')
    ->join('person_competition_statistics', 'players.personId', '=', 'person_competition_statistics.personId')
    ->addSelect(['players.*', 'teams.teamName', 'teams.teamNickname', 'teams.teamCode'])
    ->get()
    ->unique() //remove duplicates
    ->groupBy(function($item, $key) { //group familyName that starts in same letter
        return substr($item['familyName'], 0, 1);
    })
    ->map(function ($subCollection) {
        return $subCollection->chunk(4); // put your group size
    });

return $data;

Returned Error:

QueryException in Connection.php line 647:
SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'familyName' in field list is ambiguous (SQL: select CONCAT(familyName,", ",firstName) AS fullName, `players`.*, `teams`.`teamName`, `teams`.`teamNickname`, `teams`.`teamCode` from `players` inner join `teams` on `players`.`primaryClubId` = `teams`.`clubId` inner join `person_competition_statistics` on `players`.`personId` = `person_competition_statistics`.`personId` where `firstname` like %% or `familyName` like %% order by `familyName` asc)



via PenAndPapers

How to update data when its exist, and not create when its not exist, Laravel 5

I have problem in my database query
I had first import 2 entry like this THIS, and the data inserted correctly

wholesaler_id | target | week | total_transaction | rebate | total_voucher

11223344      | 100.000| 1.2017| 50.000          | 2,25    | 0 
11223344      | 100.000| 2.2017| 120.000         | 2,25    | 2700
11223344      | 100.000| 3.2017| 185.000         | 2,25    | 1462,5
11223344      | 100.000| 4.2017| 248.000         | 2,25    | 1417,5

but when i import again with additional row enter image description here, its become like this

wholesaler_id | target | week | total_transaction | rebate | total_voucher

11223344      | 100.000| 1.2017| 50.000          | 2,25    | 0 
11223344      | 100.000| 2.2017| 120.000         | 2,25    | 2700
11223344      | 100.000| 3.2017| 185.000         | 2,25    | 1462,5
11223344      | 100.000| 4.2017| 248.000         | 2,25    | 1417,5
11223344      | 100.000| 1.2017| 63.100          | 2,25    | 0 
11223344      | 100.000| 2.2017| 142.700         | 2,25    | 2700
11223344      | 100.000| 3.2017| 205.000         | 2,25    | 1462,5
11223344      | 100.000| 4.2017| 279.400         | 2,25    | 1417,5

the result i want is like this

wholesaler_id | target | week | total_transaction | rebate | total_voucher

11223344      | 100.000| 1.2017| 63.100          | 2,25    | 0 
11223344      | 100.000| 2.2017| 155.800         | 2,25    | 2700
11223344      | 100.000| 3.2017| 240.800         | 2,25    | 1462,5
11223344      | 100.000| 4.2017| 332.200         | 2,25    | 1417,5

the rebate and total voucher column isnt problem, the main problem is in total_transaction.
this is the code in my Controller function importCsv



    $voucher = Voucher::firstOrCreate(array(
     'wholesaler_id' => $wholesaler_id,
     'target' => $target,
     'week' => $week . '.' . date("Y"),
     'total_transaction' => $sum,
     'rebate' => $wholesaler_type->rebate_percentage,
     'total_voucher' => $total_voucher
     ));



via Faisal Hilmi

How do I get my user_id from the authorised client

I want to retrieve the id of the user that's currently online. But I CANNOT do it with the following code:

Route::middleware('auth:api')->post('/optionelections', function (Request $request) {
        return $request->user();
    });

The reason is because I keep getting the same unauthorised error from Laravel. I've been trying to fix this error for days and I can't seem to find a solution. So I'm trying to do it in a different way but I don't know how. I'm currently using Passport to store my token and my client_id in local storage.

this is my apply_election.vue

    import {apiDomain} from '../../config'
  export default {
    name: 'applyForElection',
    data () {
      return {
        election: {},
        newOption: {'election_id': ''},
        //this is where the user_id should come
        newOption: {'user_id': ''}

      }
    },
    methods: {
      createOption: function () {
        var itemId = this.$route.params.id
        this.newOption.election_id = itemId
        this.$http.post(apiDomain + 'optionelections', this.newOption)
          .then((response) => {
            this.newOption = {'election_id': itemId}
            alert('you applied!')
            this.$router.push('/electionsnotstarted')
          }).catch(e => {
            console.log(e)
            alert('there was an error')
            this.$router.push('/electionsnotstarted')
          })
      }
    },
    created: function () {
      var itemId = this.$route.params.id
      this.$http.get('http://www.nmdad2-05-elector.local/api/v1/elections/' + itemId)
        .then(function (response) {
          this.election = response.data
        })
    }
  }

and this in my OptionElectionsController.php

public function store(Request $request)
    {


        $optionElection = new OptionElection();
        $optionElection->user_id = $request['user_id'];
        $optionElection->option = "something";
        $optionElection->votes = 0;
        $optionElection->election_id = $request['election_id'];
        $optionElection->accepted = 0;

        if ($optionElection->save()) {


            return response()
                ->json($optionElection);

        }

    }

this is my Auth.js

export default function (Vue) {
  Vue.auth = {
    setToken (token, expiration) {
      localStorage.setItem('token', token)
      localStorage.setItem('expiration', expiration)
    },
    getToken () {
      var token = localStorage.getItem('token')
      var expiration = localStorage.getItem('expiration')

      if (!token || !expiration) {
        return null
      }
      if (Date.now() > parseInt(expiration)) {
        this.destroyToken()
        return null
      } else {
        return token
      }
    },
    destroyToken () {
      localStorage.removeItem('token')
      localStorage.removeItem('expiration')
    },
    isAuthenticated () {
      if (this.getToken()) {
        return true
      } else {
        return false
      }
    }
  }

  Object.defineProperties(Vue.prototype, {
    $auth: {
      get: () => {
        return Vue.auth
      }
    }
  })
}



via hxwtch

Advertisement