mercredi 5 août 2015

how to configure .htaccess to such that I can have access to subfolders and subdomains in a Laravel project


I currently build most of my apps with Laravel 5.1 and host them on share hosting. The major challenge I have come across is that I cannot have access to sub folders e.g. http://ift.tt/1DpxEGu, also when I try to access a sub-domain for example admins.mydomain, I keep having Internal server error(error 500).
I need help to get over this, thanks.



via Chebli Mohamed

Using foreach with form submit


I am trying to submit multiple rows using the foreach loop in my method. However when I press submit I am getting this array to string error. How do I fix this error?

Error

Array to string conversion

HTML

{!! Form::open(array('id'=> 'form1')) !!}
    <div class = "form-group">
        <div class="col-md-6">
            {!! Form::label('title','Title:', ['class' => 'col-md-4 control-label']) !!}
            {!! Form::checkbox('interest_id', '1', ['class' => 'formclick submit']) !!}
        </div>
    </div>

    <div class = "form-group">
        <div class="col-md-6">
            {!! Form::label('title','Title:', ['class' => 'col-md-4 control-label']) !!}
            {!! Form::checkbox('interest_id', '2',['class' => 'formclick submit']) !!}
        </div>
    </div>
    <input id = "submit_me" type="button" value="Click Me!"  />
{!! Form::close() !!}

Controller

public function store(InterestRequest $interest) {

    $interests = Request::all();
    $interests = Request::all();

    foreach ($interest-> $interests as $inter) {
        $interest = new Follower(array(
            'user_id' => $interest->get('interest_id'),
            'follower_id'  => Auth::id()
        ));

        $inter->save();

    }
}



via Chebli Mohamed

How to update the cache value when database has change value of same data which is stored in cache


If i am using laravel 4.2 caching mechanism like bellow.

$users = DB::table('users')->remember(10)->get();

As i understand cache mechanism query execute one's and story it's value to cache and return data from cache upto 10 minutes.

But my problem is one's query will be executed and data stored it's cache inbetween user table updates it's value then how may i check and update cache value so i can get updated data.

Any one have idea any suggestion please let me know...?



via Chebli Mohamed

Generate a date schedule that executes only on weekdays


I have a date schedule function in PHP which aims to execute only on working days. The code I have at the moment is generating the schedule for all days of the week so the while statement doesn't seem to working and I'm not sure why.

I'm a student, so I'm not very experienced with this kind of thing. Here is the code I have so far:

public static function generate_date_schedule($tasksperdayschedule, $startdate) {
    $schedule = [];

    $date = clone $startdate;

    foreach ($tasksperdayschedule as $numberoftasks) {
        $day = (int)$date->format('N');

        // Skip weekend days.
        while ($day > 5) {
            $date->add(new DateInterval('P1D'));
            $day = (int)$date->format('N');
        }

        $schedule[$date->format(self::DATE_FORMAT)] = $numberoftasks;

        $date->add(new DateInterval('P1D'));
    }

   return $schedule;

It is probably something very small I am missing, but any help would be appreciated! Thanks



via Chebli Mohamed

Should I use Postgres's roles system for a web app's user management?


Postgres already has fully featured user management system. Why should I duplicate this functionality and use another one on top of that? And I think this is the right place to manage users & groups as it allows fine-grained control. Am I wrong? Is there some php libraries that already have done that?



via Chebli Mohamed

Select box doesn't work


So I have a select box built with :

$form->addElement(new Element\Select("Existing projects:", "Existing_Projects", $options, array("onchange"=>"this.form.submit()")));

And here is the code to get the projects.But somehow it doesn't work.When I click on 'option2' option,it gets back to 'option1'.

$projects = get_projects();
$options = array();
foreach ($projects as $project){
    if ( $project[2] == $Existing_Projects )
        $option = $project ; break ;
    array_push($options, $project[1]);
    }
$options = array(10=>"option1",5=>"option2", "value"=>"selected", 6=>"option3");
//print_r($options);
$form = new Form("project-form");//"prevent" => array("bootstrap", "jQuery"),
$form->configure(array(
    "action" => "right.php?target=management/platform"
));

What is wrong?



via Chebli Mohamed

Match exact word with any character regex


How to match exact word contains any special character ?

$string = 'Fall in love with #PepsiMoji! Celebrate #WorldEmojiDay by downloading our keyboard @ http://bit.ly/pepsiKB & take your text game up a notch. - teacher';

preg_match("/\b#worldemojiday\b/i",$string); //false

I want to match exact word containing any character. Like if I want to match word 'download' in this string, It should return false

preg_match("/\bdownload\b/i",$string); //false

But when I search for downloading, It should return true.

Thanks



via Chebli Mohamed