mercredi 22 juin 2016

How to add custom variable in form tag in twig(Laravel)?

How to add custom variable in form tag in twig(Laravel)? For example:

{!! Form::select('slt-mv-driver-name-****[]', $a_slt_user, Input::old('slt-mv-driver-name-1', isset($s_unique_id) ? $a_details_result->data->a_drivers : '') , array('class'=>'form-control multiselect slt-mv-driver-name','id'=>'slt-mv-driver-name-1', 'multiple' => 'multiple')) !!}

In above tag I want to put the value of $abcd dynamically. How can I do that?



via Chebli Mohamed

The requested URL /laravel-filemanager was not found on this server in UniSharp/laravel-filemanager

I am using UniSharp/laravel-filemanager and I've done all steps to install it , but when I want to use it i face this error :

I am using laravel 5.1 on wamp server

Not Found

The requested URL /laravel-filemanager was not found on this server.

Apache/2.4.9 (Win64) PHP/5.5.12 Server at localhost Port 80



via Chebli Mohamed

How can i rename directory in Laravel5.1

How can I rename directory on public , In my controller ? I read Laravel document but File class doesn't have rename .

File::move();

I just need rename , I cant move my files to an other Folder



via Chebli Mohamed

mardi 21 juin 2016

Laravel 5.1: Query Builder Select Multi table and SUM result

My code

DB::table('users_tb')->leftjoin('device_tb', 'device_tb.user_id', '=', 'users_tb.user_id')
->leftjoin('part_tb', 'device_tb.device_id', '=', 'part_tb.device_id')
->select('users_tb.user_name', DB::raw("(SELECT COUNT(part_tb.id) FROM part_tb) AS counter"))
->where('users_tb.level', '>', 7)
->havingRaw("(SELECT COUNT(part_tb.id) FROM part_tb) > 0")
->groupBy('device_tb.device_id')
->orderBy('users_tb.user_name')
->get()->toArray();

My result:

Name1 - 3
Name1 - 4
Name1 - 3
Name2 - 11
Name2 - 2

How i can SUM counter? Example:

Name1 - 10 (3+4+3)
Name2 - 13 (11 + 2)

Somebody help me, please!!



via Chebli Mohamed

how to validate nested json using request file in laravel 5.1

This is my form post data ,I want to validate this post data using custom validation request class.I am able to check all the validation rules against normal data but unable to check the same kind of rules to secondatry_users.I need my request files also apply rules on secondary_users data defined in the rules method

[
  "first_name" => "Shubham"
  "last_name" => "Jolly"
  "email" => "sachinu.meta@gmail.com"
  "mobile" => ""
  "status" => "1"
  "role" => "7"
  "trial" => ""
  "password" => "HQfZ6$px"
  "autogenerate" => "1"
  "secondary_users" => "{
            "1":{
            "recordID":1,
            "secondaryUserFirstName":"shubhamiii",
            "secondaryUserLastName":"s",
            "secondaryUserEmail":"shubha.jolly@daffodilsw.com",
            "secondaryUserMoble":"",
            "secondaryUserStatus":"1",
            "secondaryUserTrial":"",
            "secondaryUserPassword":"SyEsM#w2",
            "tag":""
            },
            "2":{
            "recordID":2,
            "secondaryUserFirstName":"shubha",
            "secondaryUserLastName":"jolly",
            "secondaryUserEmail":"shubham.jolly@daffodilsw.com",
            "secondaryUserMoble":"9896156667",
            "secondaryUserStatus":"1",
            "secondaryUserTrial":"2",
            "secondaryUserPassword":"aasM#w2",
            "tag":""
            }
        }"
]

How to validate this data i have created rules but its not working for the secondary_users input.

public function rules() {                 
     // Basic Property Validation  
    $rules = [
    'first_name' => 'required|max:255',
    'email' => 'required|email|max:255|unique:users',
    'role' => 'required',
    'status' => 'required',
    'password' => 'required|min:8|max:30|http://regex:/^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[!@#$%^&*()+]+.*)[0-9a-zA-Z\w!@#$%^&*()+]{8,}$/',
     'trial' => 'numeric',
     ];
      //secondary users validation
    if (isset($secondaryUser) && !empty(json_decode($secondaryUser))) {
         $usersArray = json_decode($secondaryUser);
             foreach ($usersArray as $key => $value) {
                   $rules['secondary_users.' . $key . '.secondaryUserFirstName'] = 'required|max:255';
                   $rules['secondary_users.' . $key . '.secondaryUserEmail'] = 'required|email|max:255|unique:users';
                   $rules['secondary_users.' . $key . '.secondaryUserStatus'] = 'required';
                   $rules['secondary_users.' . $key . '.secondaryUserTrial'] = 'numeric';
                   $rules['secondary_users.' . $key . '.secondaryUserPassword'] = 'required|min:8|max:30|http://regex:/^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[!@#$%^&*()+]+.*)[0-9a-zA-Z\w!@#$%^&*()+]{8,}$/';

                }
            }
        return rules;
        }



via Chebli Mohamed

Export data to Excel in Laravel

I want to make export data into excel in my project, i have made it, but after I check the results, the results doesnt like what I want. here I would like to make a result there is a title table.

This code my controller:

public function getExport(){
        Excel::create('Export data', function($excel) {

        $excel->sheet('Sheet 1', function($sheet) {

            $products=DB::table('log_patrols')
            ->join("cms_companies","cms_companies.id","=","log_patrols.id_cms_companies")
            ->join("securities","securities.id","=","log_patrols.id_securities")
            ->select("log_patrols.*","cms_companies.name as nama_companies","securities.name as nama_security")
            ->get();
                foreach($products as $product) {
                 $data[] = array(
                    $product->date_start,
                    $product->date_end,
                    $product->condition_status,
                    $product->nama_security,
                    $product->nama_companies,
                );
            }
            $sheet->fromArray($data);
        });
    })->export('xls');
    }

this my problem result : result

and it should be :

should

my problem is how to change the number into text what i want in the header table.

what improvements do i have to make to the code to achieve my goal?

NB : i use maatwebsite/excel



via Chebli Mohamed

Randomize order of divs in a form

I have looked around at the numerous questions regarding randomizing divs and have tweaked some code that does the job almost perfectly.

I have a form that contains 10 multichoice questions, on the page load I am wanting to randomize the order that they appear in; but using the code below they end up in a random order, with the submit button of the form above them.

HTML

<form method="POST" action="http://ift.tt/28MEqsv" accept-charset="UTF-8">    

    <div class="form-group">
        <h3>Multiple Choice</h3>
    </div>

    <div class='form-group question'>
        <label for="multi1">1) What is our server&#039;s genre?</label>
        <div class='radio'><label><input name="multi1" type="radio" value="a" id="multi1"> Light Roleplay</label></div>
        <div class='radio'><label><input name="multi1" type="radio" value="b" id="multi1"> Deathmatch/Freeroam</label></div>
        <div class='radio'><label><input name="multi1" type="radio" value="c" id="multi1"> Heavy Roleplay</label></div>
        <div class='radio'><label><input name="multi1" type="radio" value="d" id="multi1"> Drifting</label></div>
    </div>

    <div class='form-group question'>
        <label for="multi2">2) An advanced knowledge of which of the following languages is required on our server?</label>
        <div class='radio'><label><input name="multi2" type="radio" value="a" id="multi2"> Russian</label></div>
        <div class='radio'><label><input name="multi2" type="radio" value="b" id="multi2"> English</label></div>
        <div class='radio'><label><input name="multi2" type="radio" value="c" id="multi2"> Latvian</label></div>
        <div class='radio'><label><input name="multi2" type="radio" value="d" id="multi2"> All languages are acceptable</label></div>
    </div>

    <div class='form-group question'>
        <label for="multi3">3) Which of the following activities are controlled because of Rule 6?</label>
        <div class='radio'><label><input name="multi3" type="radio" value="a" id="multi3"> Torturing a character</label></div>
        <div class='radio'><label><input name="multi3" type="radio" value="b" id="multi3"> Character killing another player's character</label></div>
        <div class='radio'><label><input name="multi3" type="radio" value="c" id="multi3"> Disregarding another player's out-of-character communication</label></div>
        <div class='radio'><label><input name="multi3" type="radio" value="d" id="multi3"> Ignoring an administrator's ruling</label></div>
    </div>

    <div class='form-group question'>
        <label for="multi4">4) If you wish to steal a property from another player, which of the following is the correct way to do so?</label>
        <div class='radio'><label><input name="multi4" type="radio" value="a" id="multi4"> Obtain administrator permission beforehand by using the report system in-game</label></div>
        <div class='radio'><label><input name="multi4" type="radio" value="b" id="multi4"> Roleplay it first, then ask for an administrator to transfer the property</label></div>
        <div class='radio'><label><input name="multi4" type="radio" value="c" id="multi4"> Have the stolen property transferred by filling out the application</label></div>
        <div class='radio'><label><input name="multi4" type="radio" value="d" id="multi4"> None of the above</label></div>
    </div>

    <div class='form-group question'>
        <label for="multi5">5) Which of the following activities is against the rules?</label>
        <div class='radio'><label><input name="multi5" type="radio" value="a" id="multi5"> Killing several gang members in a drive-by without having interacted with them at all beforehand</label></div>
        <div class='radio'><label><input name="multi5" type="radio" value="b" id="multi5"> Requiring that anyone who joins your organization agrees to a CK contract</label></div>
        <div class='radio'><label><input name="multi5" type="radio" value="c" id="multi5"> Demanding a reason for being killed from your killer through out-of-character communication</label></div>
        <div class='radio'><label><input name="multi5" type="radio" value="d" id="multi5"> Robbing someone's character near the boardwalk</label></div>
    </div>

    <div class='form-group question'>
        <label for="multi6">6) Which of the following player names would be acceptable?</label>
        <div class='radio'><label><input name="multi6" type="radio" value="a" id="multi6"> Wei Jiang</label></div>
        <div class='radio'><label><input name="multi6" type="radio" value="b" id="multi6"> Asuka Kasen</label></div>
        <div class='radio'><label><input name="multi6" type="radio" value="c" id="multi6"> Cristiano Ronaldo</label></div>
        <div class='radio'><label><input name="multi6" type="radio" value="d" id="multi6"> Raimonds Vejonis</label></div>
    </div>

    <div class='form-group question'>
        <label for="multi7">7) When is it acceptable to completely ignore another player&#039;s out-of-character communication?</label>
        <div class='radio'><label><input name="multi7" type="radio" value="a" id="multi7"> Always</label></div>
        <div class='radio'><label><input name="multi7" type="radio" value="b" id="multi7"> If they are breaking server rules or encouraging the breaking of server rules</label></div>
        <div class='radio'><label><input name="multi7" type="radio" value="c" id="multi7"> Anytime, as long as it isn't to tell a player why you killed them</label></div>
        <div class='radio'><label><input name="multi7" type="radio" value="d" id="multi7"> Never</label></div>
    </div>

    <div class='form-group question'>
        <label for="multi8">8) You are killed. You see your killer later, yell out to them your reasoning for killing them, and kill them to take revenge. Is that acceptable?</label>
        <div class='radio'><label><input name="multi8" type="radio" value="a" id="multi8"> No, because you did not roleplay with them sufficiently beforehand, so you are guilty of deathmatching</label></div>
        <div class='radio'><label><input name="multi8" type="radio" value="b" id="multi8"> Yes, because you had a solid reason for killing them</label></div>
        <div class='radio'><label><input name="multi8" type="radio" value="c" id="multi8"> No, because killing another player just for killing you is not allowed</label></div>
        <div class='radio'><label><input name="multi8" type="radio" value="d" id="multi8"> Yes, as long as you interacted with them before killing them</label></div>
    </div>

    <div class='form-group question'>
        <label for="multi9">9) Which of the following could be classified as powergaming?</label>
        <div class='radio'><label><input name="multi9" type="radio" value="a" id="multi9"> Killing another player as part of a contract killing</label></div>
        <div class='radio'><label><input name="multi9" type="radio" value="b" id="multi9"> Roleplaying acting on instructions from an NPC of your own creation</label></div>
        <div class='radio'><label><input name="multi9" type="radio" value="c" id="multi9"> Helping a friend evade police who asked for your help over an out-of-character form of communication</label></div>
        <div class='radio'><label><input name="multi9" type="radio" value="d" id="multi9"> Committing a crime in an unrealistic area</label></div>
    </div>

    <div class='form-group question'>
        <label for="multi10">10) Which of the following could be classified as metagaming?</label>
        <div class='radio'><label><input name="multi10" type="radio" value="a" id="multi10"> Assuming a character's gang affiliations by their clothing</label></div>
        <div class='radio'><label><input name="multi10" type="radio" value="b" id="multi10"> Identifying an organization in-game based on publicly available information in an in-character section of the forums</label></div>
        <div class='radio'><label><input name="multi10" type="radio" value="c" id="multi10"> Sharing potentially sensitive in-character information about an organization out of character</label></div>
        <div class='radio'><label><input name="multi10" type="radio" value="d" id="multi10"> Accepting money in-game to kill a target</label></div>
    </div>

    <div class='form-group'>
        <input class="btn btn-primary" type="submit" value="Submit">
    </div>

    </form>

jQuery that I am using to randomize them

$.fn.randomize = function(selector){
    (selector ? this.find(selector) : this).parent().each(function(){
        $(this).children(selector).sort(function(){
            return Math.random() - 0.5;
        }).detach().appendTo(this);
    });

    return this;
};

$('form').randomize('.question');
$('.question').randomize('.radio');

As per the screenshot below, you can see what I mean regarding the submit button:

Submit button above the questions

How can I get the questions randomized like I have done, without the submit button moving up to the top too?



via Chebli Mohamed