mercredi 1 août 2018

Laravel HTTP 500 Error after a while

I have problem with laravel in shared hosting. I deployed it on cPanel and was successfully running. After 4 or 5 hours I got HTTP 500 error. I checked error log and I figured out that some vendor files are removed given the following stacktrace: Uncaught class: Illumination\FileSystem\FileSystem.php



via Chebli Mohamed

vue2 file api file uploading not works

I'm trying to make a image upload with vue2 and laravel5 REST Api. so that I tried to send the file to post method

HTML

<form @submit.prevent="addStaff">
    <div class="form-group">
              <div v-if="!staff.pic">
        <h2>Select an image</h2>
        <input type="file" @change="onFileChange">
      </div>
      <div v-else>
        <img :src="staff.pic" />
        <button @click="removeImage">Remove image</button>
      </div>
              </div>
<button type="submit">Submit</submit>
</form>

Here is my Client side code

handleFileUpload(e){

        this.staff.pic = e.target.files[0];
},

addStaff(){
fetch('api/staffprofile', {
          method: 'post',
          body: JSON.stringify(this.staff),
          headers: {
            'content-type': 'application/json'
          }
        })
          .then(res => res.json())
          .then(data => {
               console.log(res.data); 
}
    }

Here is my server side code

$image = $request->file('pic');

$filename = time() . '.' . $image->getClientOriginalExtension();
$location = public_path('img/staffpic/' . $filename);

Image::make($image)->resize(800, 400)->save($location);
$post->image = $filename;

When i'm trying to upload file with Postman it works but in case of posting data with on site it shows 500 error

any Help?



via Chebli Mohamed

Returning new Laravel model ID before saving

I've seen similar questions for other frameworks but I cant seem to find an answer for Laravel.

What is the best practise / cleanest solutions to achieve my goal.

At the moment lets say I have a model called Site.

My site model has a column called prefix which is just a few capital letters generated by the site name plus the new site id so for example, row 1 with a site name of 'clare' becomes 'CLA1' and 'pencet' becomes 'PEN2'.

My issue is that I need the new row id to generate the prefix, which means at the moment I have to save it, then re-save it like so.

$site = new Sites;
$site->name = 'clare';
$site->save();
//Now that we have saved, we can use the new id to create the prefix and save again
$site->prefix = strtoupper(substr($site, 0, 3)) . $site->id;
$site->save();

I hate the fact I have to re-save it again once its initially been saved because I need the id, what is the best way to achieve this goal? Is it possible to return the new model ID before it saves?

I know I can do stuff like get a count of all of the rows and get the ID that way instead, but i'm generally looking for the best, cleanest solutions to achieve this.



via Chebli Mohamed

Laravel pusher broadcast 500 error: illegal offset type in isset or empty

Try to create random chat user with pusher on laravel. When I try to broadcast "Session" (It means connection) It return to me Failed to load resource: the server responded with a status of 500 (Internal Server Error) but error appear only for user who create the session. I try to explain how it works. I use Vue JS and Laravel. All starts when user click "Start chat" in some category. After that I check, is there already created by somebody chat request in this chat category in chatrequests table. If it is - this user create a "session" for them with data "id" "user1_id", 'user2_id" to sessions table and the chat window starts for them. (User that created request for chat wait for connection with every second request to sessions table to check is there already session created by another user). So, after all this things I have the data in sessions table and chatrequest row deleted from chatrequests table. The problem appear when I try to broadcast via Pusher this session with data: $session, $session_by: broadcast(new ConnectionEvent($modifiedConnection, $connection_by)); So, the data that I send to Pusher is:

'id' => $this->id,
'users' => [$this->user1_id, $this->user2_id]
'session_by => auth()->id() (because this function always called by the person who create the session)

After this I have the 500 with error:

message: "Illegal offset type in isset or empty", exception: "ErrorException",… "ErrorException" "/Users/jsk89/Sites/chat/vendor/laravel/framework/src/Illuminate/Queue/QueueManager.php" line 137. message "Illegal offset type in isset or empty"

One important thing: all the data successfully saved in the DB and the error appear only to user who create the session. Pusher keep silence.

PS: Pusher settings are correct because Presence event of connected users to the project broadcasting successfully.

I don't find my problem in the internet. Maybe somebody knows how to fix this. With hope...



via Chebli Mohamed

Laravel project transfer

I worked as a prefect on the Laravel on my laptop. But when I wanted to transfer the project to another machine, an error appeared: "The MAC is invalid". What I can do with it?



via Chebli Mohamed

Laravel undefined variable in view, Laravel 5.2 using AdminLTE

I am getting an error in laravel 5.2 on the telegram view with an undefined variable posts. I am using AdminLTE templates and here is my code so far:

on my Controller:

public function storeMessage(Request $request)
    {
        $request->validate([
            'email' => 'required|email',
            'message' => 'required'
        ]);

        $text = "[HEADLINE] Informasi Portal Beasiswa\n"
            . "<b>Email Address: </b>\n"
            . "$request->email\n"
            . "<b>Message: </b>\n"
            . $request->message;

        Telegram::sendMessage([
            'chat_id' => env('TELEGRAM_CHANNEL_ID', ''),
            'parse_mode' => 'HTML',
            'text' => $text
        ]);

        return redirect('beasiswa');
    }

and my error like bellow: enter image description here



via Chebli Mohamed

Broken style in laravel email notification

I send several line of list:

->line(' - Submit your own recipes and link to your own site.Get customized newsletters based on your food and drink profile.')
->line(' - Take part in contests with amazing prizes and get invited to events!')
->line(' - Are you a business or brand? Create your own profile to promote to your audience!')

But last item of list get broken styles:

Image

How fix it?

Email styles



via Chebli Mohamed