Git Product home page Git Product logo

laravel-blog's Introduction

Laravel 10.x blog

The purpose of this repository is to show good development practices on Laravel as well as to present cases of use of the framework's features like:

Beside Laravel, this project uses other tools like:

Some screenshots

You can find some screenshots of the application on : https://imgur.com/a/Jbnwj

Installation

To create your development environment follow these instructions.

Setting up your development environment on your local machine:

$ git clone https://github.com/guillaumebriday/laravel-blog.git
$ cd laravel-blog
$ cp .env.example .env
$ php artisan key:generate
$ php artisan horizon:install
$ php artisan telescope:install
$ php artisan storage:link

Mailer

You can use Mailpit to test your emails in development.

Once installed, open http://localhost:8025.

Before starting

You need to run the migrations with the seeds :

$ php artisan migrate --seed

This will create a new user that you can use to sign in :

email: [email protected]
password: 4nak1n

And then, compile the assets :

$ yarn dev # or yarn watch

Starting job for newsletter :

$ php artisan tinker
> PrepareNewsletterSubscriptionEmail::dispatch();

Useful commands

Start Laravel Horizon:

$ php artisan horizon

Seeding the database :

$ php artisan db:seed

Running tests :

$ php artisan test

Running Laravel Pint :

$ ./vendor/bin/pint --verbose --test

Generating backup :

$ php artisan vendor:publish --provider="Spatie\Backup\BackupServiceProvider"
$ php artisan backup:run

Generating fake data :

$ php artisan db:seed --class=DevDatabaseSeeder

Discover package

$ php artisan package:discover

In development environment, rebuild the database :

$ php artisan migrate:fresh --seed

Accessing the API

Clients can access to the REST API. API requests require authentication via Bearer token.

Generate a new token:

curl --location --request POST 'laravel-blog.test/api/v1/authenticate?email=your_email&password=your_password' \
     --header 'X-Requested-With: XMLHttpRequest'

And now you can use the meta.access_token key as your Bearer token:

curl --location 'laravel-blog.test/api/v1/posts' \
      --header 'X-Requested-With: XMLHttpRequest' \
      --header 'Authorization: Bearer access_token'

API are prefixed by api and the API version number like so v1.

Do not forget to set the X-Requested-With header to XMLHttpRequest. Otherwise, Laravel won't recognize the call as an AJAX request.

To list all the available routes for API :

$ php artisan route:list --path=api

Contributing

Do not hesitate to contribute to the project by adapting or adding features ! Bug reports or pull requests are welcome.

License

This project is released under the MIT license.

laravel-blog's People

Contributors

guillaumebriday avatar ivothgle avatar khoinv avatar makstech avatar matiaslauriti avatar ph-7 avatar renovate-bot avatar tompenzer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

laravel-blog's Issues

socket.io not include

i open the article detail page and found error
socket.io.js:1 Failed to load resource: net::ERR_CONNECTION_REFUSED

NOAUTH Authentication required.

In the log file, laravel.log, this error continuously gets marked. It increases the log file size increasingly multiple times per second, taking up the entire size of the server.

I went into the redis docker container, checked to see if there was a password, which there was not.
Also, I checked if there were any configuration file for redis which would be requiring a password -- there is no configuration file.

Do you have any idea why this could be?

[2019-01-16 20:32:39] local.ERROR: NOAUTH Authentication required. {"exception":"[object] (Predis\\Response\\ServerException(code: 0): NOAUTH Authentication required. at /application/vendor/predis/predis/src/Client.php:370)
[stacktrace]
#0 /application/vendor/predis/predis/src/Client.php(335): Predis\\Client->onErrorResponse(Object(Predis\\Command\\ListLength), Object(Predis\\Response\\Error))
#1 /application/vendor/predis/predis/src/Client.php(314): Predis\\Client->executeCommand(Object(Predis\\Command\\ListLength))
#2 /application/vendor/laravel/framework/src/Illuminate/Redis/Connections/Connection.php(114): Predis\\Client->__call('llen', Array)
#3 /application/vendor/laravel/framework/src/Illuminate/Redis/Connections/Connection.php(214): Illuminate\\Redis\\Connections\\Connection->command('llen', Array)

docker-compose run --rm blog-server php artisan migrate --seed not working

When run this command I get this error message

 Illuminate\Database\QueryException  : SQLSTATE[HY000] [1130] Host '172.18.0.8' is not allowed to connect to this MySQL server (SQL: select * from information_schema.tables where table_schema = laravel-blog and table_name = migrations)

  at /application/vendor/laravel/framework/src/Illuminate/Database/Connection.php:664
    660|         // If an exception occurs when attempting to run a query, we'll format the error
    661|         // message to include the bindings with SQL, which will make this exception a
    662|         // lot more helpful to the developer instead of just the database's errors.
    663|         catch (Exception $e) {
  > 664|             throw new QueryException(
    665|                 $query, $this->prepareBindings($bindings), $e
    666|             );
    667|         }
    668|

  Exception trace:

  1   Doctrine\DBAL\Driver\PDOException::("SQLSTATE[HY000] [1130] Host '172.18.0.8' is not allowed to connect to this MySQL server")
      /application/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:31

  2   PDOException::("SQLSTATE[HY000] [1130] Host '172.18.0.8' is not allowed to connect to this MySQL server")
      /application/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:27

  Please use the argument -v to see more details.

post comment not work

Hi, test your blog and i try to comment but i got error -> Unauthenticated. i'm allready logged in..

i have some settings wrong or that is bug ?

MySQL Connection Refused AND SQLSTATE[HY000] with Docker 0.0.0.0 SQL

image

Inside .env, when I have the MySQL DB_HOST=mysql, and I try to run a migration, I get: SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known (SQL: select * from information_schema.tables where table_schema = laravel-blog and table_name = migrations)

image
But I am able to log in and out of the website, etc.

When I change the DB_HOST=mysql to DB_HOST=0.0.0.0 I am able to run migrations but it throws a Cannot Connect error when I try to log in and out.

image

When I try to log in
Illuminate \ Database \ QueryException (2002) SQLSTATE[HY000] [2002] Connection refused (SQL: select * from userswhereemail= [email protected] limit 1)

image

https://paste.ofcode.org/Gkk4um4UuMy7d9iW2qmfyH

My docker...
image

styles

it doesn't have a file of style in folder /public.

Feature proposals: non-social mode, contact form

Hi Guillaume,

In modifying this project for my personal uses, a couple features seem like they might be appealing to users of the project for relatively little effort:

  1. Add a .env variable for SOCIAL_FEATURES=true, and if you set it to false, self-registration routes are disabled, and commenting and liking are no longer rendered to the views or queried in the controllers. I've hard-coded most of those changes in my fork, but it would be relatively straightforward to add conditionality where needed keyed off the .env and make that a configuration option.

  2. I've added a (fully localized) lightweight implementation of a contact form, implemented with a new 'Can be contacted' role assigned to users you want to appear in a recipient selector on the contact page if there are more than one user with the role. Upon submission, the form's post contents get emailed out to the corresponding user's email. Optionally, in my fork, I've also replaced the 'email' displayed on user profiles with a 'title' string column I added to the users table (in addition to a 'blurb' text column, and a media_id integer foreign key reference to a media gallery item for a profile pic), but an alternative might be to put a link to contact.user, $user there (a separate route for contacting a particular recipient, i.e. /contact/user/1). I say lightweight because the contact form submissions are neither stored in the DB, nor managed in the admin dashboard. They just get emailed right out and that's it.

I'd be happy to contribute these features if you'd be interested, though I'm ashamed to say I can't figure out how to submit a PR, since I can't make branches.

use multiple docker containers instead of just one

Hi there! First of all this is not a bug so feel free to close it at any point.

I thank for your contribution with this project, I am at a time in my dev life where I am diving into containerization and trying to wrap my mind around many things such as Terraform, Nomad, Jenkins, CI and Ansible

I have it in my mind that as much as possible everything should be a container and containers should be running only one process. I'm still confused about this.. don't all contains housing web apps need to run Nginx at the very least? And for sure any php app needs to also run php.. which makes the minimum configuration for a Docker container housing a Laravel project to include Nginx + Php.

But Redis could be its own Docker container, and so could Mysql.. right? This is good practice.. a bit more overhead but if you ever wanted to scale and have 3 of each Mysql/Redis and only 2 web servers.. and load balance the whole thing.. then starting with each service as a separate container would be a good idea to prepare for the future. Do you agree here?

I am wondering.. how easily would it be to modify your package so that as many as possible docker containers are used. It should be as simple as splitting them off into multiple docker-compose files.. creating multiple images.. and then in the database.php of Laravel (or the .env file) adjust the hosts for redis and mysql ? Also you'd have to open up the right ports on the containers housing those

Would love to hear your thoughts

Also.. is this setup production ready? I mean.. can I deploy this docker to production and expect it to work? I'm still very confused how nginx does its magic here and how the outside world can access websites inside containers as easily as if they are installed on the base OS.

Thanks for your time!!

Doctrine\DBAL\Driver\PDOException:

Hey ! When I run $ docker-compose run --rm blog-server php artisan migrate --seed
I get the following error message:

Doctrine\DBAL\Driver\PDOException::("SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'json not null, custom_propertiesjson not null,responsive_images json not n' at line 1") /private/var/www/laravel.local/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php : 82

Erro on create a new post

The rule "'slug' => 'unique:posts,slug,' . optional($this->post)->id," is create an exception because the id is empty.
Database: postgresql

Login failed with github

Hello guillaume,
I just report than I cant connect with my github account because my "Name" is not filled on my profil page.
I think you have to change to not required on the name.

Issue displaying the card in chrome

In chrome the way the posts are displaying are in one column. But in the other browsers, it is side by side. I google it and I found that setting orphans: 1; widows:1; in the .card_column, will fix this issue. It is more of a bootstrap issue than this code. May be it will help someone.

Comment Echo not working

Hi, me again. Comment posting is working but the Echo listen function does not work.

I have the commands npm star, artisan queue: work and redis running but the message does not reach the listen function.

In the console of nom star it shows the following:

[12:36:00] - NA8nxWOwN-wyy5j6AAAB left channel: post.2 (transport close)
[12:36:01] - tDfTVxtoDfBjl0ICAAAD joined channel: post.2

And in the queue: work console it shows the following:

[33m [2018-05-16 17:36:12] [VUe75mg1ITslY99WvAKfPJByWH63srwo] Processing: [39m App \ Events \ CommentPosted
[32m [2018-05-16 17:36:12] [VUe75mg1ITslY99WvAKfPJByWH63srwo] Processed: [39m App \ Events \ CommentPosted

I do not know what to review. Please help.

Include the file permission chmod 777 command to the readme file

Hi,
You are creating a nice application.

Following your installation instructions, I was able to install your application on my PC.
At the beginning I faced UnexpectedValueException and running “docker-compose run --rm --no-deps blog-server chmod -R 777 storage/” helped and, right away, I got another Illuminate\Database\QueryException. I got rid of it by seeding the DB . So, if we run a file permission, seed DB, and only then access the app, we should not get these exceptions.
That’ why I have just proposed to include file permission chmod 777 command to the readme file, so that people would spend less time for installing your app. Also it would be nice to place seeding db before accessing the app.

PHPUnit Testing Fail?

In trying to use phpunit inside any of the docker containers, I cannot. It yells at me to do a composer install but it mainly talks about how it can't find the current location. When I enter any besides nginx container, I get, shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory immediately when using docker exec -it .../bin/bash.

Do you have a way to do Unit tests?

Then when trying outside of docker and inside my local machine, no test passes. It seems like it is because I am not running the command from inside docker.
image
image

I'd possibly like to help with this project, as I am starting to use this as the base of one of my projects.

Post comments need to be strengthened

The comment's broadcast only handles the addition, the number of comments on the page is not changed, and the comment is not synchronized when deleted

Get thumbnail query getting executed multiple time

On the home page if you check in debugger bar you will find that the query to get the post thumbnail is getting executed multiple time . So if you have multiple post with thumbnail , then 2 query get executed per post to get thumbnail.

unauthorized

when i run docker-compose it says error : service 'blog-server' failed to build. unauthorized : incorrect username or password. how to make this command authorized ? thanks

Make time optional or pre-fill date/time.

It's a great job. Great case study. Thanks.

I'd suggest, regarding UX, to autocomplete date/time when creating a new post. Because we'd want to publish with today date most of the times. Also, time may not be important for some of us. I don't really like to fill it, but it happens to be mandatory. Really, I'd just skip it. So, having it pre-filled would help on that, making it easy to just skip it.

You know? After installing, removing the time from the front-end view it's trivial. Removing it from the admin maybe it's trivial too, but I'd tend not to touch the admin code. Usually, I'd just care about the frontend changes. And that leads me to another proposal: just like in wordpress, it would be nice to decouple the front-end theme. I mean, saving the views in a folder, and create a template selector in the admin area. It's just an idea. I don't know if you plan to make this grow.

Error deleting an image

When you delete an image from the media it is not removed from the associated posts generating an error in the home.

I have a question

I ask you a question for a doubt that I have, why do you use the fields posted_at or registered_at instead of created_at?

Using with Laradock

Hello!

First of all, thx for your work and this repo.
I use Laradock docker configuration for multiple projects: https://laradock.io/getting-started/#B

When I start docker-compose command in this repo I see this error:

Status: Downloaded newer image for redis:alpine
Creating laravel-blog_mysql_1      ... error
Creating laravel-blog_mysql-test_1 ... 
Creating laravel-blog_redis_1      ... 

ERROR: for laravel-blog_mysql_1  Cannot start service mysql: driver failed 
programming external connectivity on endpointCreating laravel-blog_mysql-test_1 ... done
Creating laravel-blog_redis_1      ... done

ERROR: for mysql  Cannot start service mysql: driver failed programming external 
connectivity on endpoint laravel-blog_mysql_1
(0c8fbc7a8fd55ccd1bb7a72a5728c791bd073f0174b360e390a2363ade523b0d): Bind 
for 0.0.0.0:3306 failed: port is already allocated
ERROR: Encountered errors while bringing up the project.

When I docker-compose down in Laradock and docker-compose up yours, all works fine, BUT I can't use my own project 😞 I want to start both projects on my host machine.

Also I have differences in my Laradock conf:

  • PHP 7.2
  • MySQL 5.7

Any ideas? Build MySQL with another port?

No admin? No posting?

After logging into the site, which works, I cannot access any admin panel. When I use /admin/posts it tells me that I do not have access. There also is no place where I can add posts.

Cross-Site Scripting issue

When you use the payload {{ alert(1) }} in the username, post title or comment field the alert box will pop. It also pops on the admin dashboard, making this a target for blind XSS. I have tested this and got a screenshot of the logged in admin dashboard using XSShunter payload.

I have edited the {{ $user-name }} to {!! $user-name !!} and it still pops an alert message. You can check it on https://x1m.nl/blog , there is a live Proof of Concept there.

https://x1m.nl/blog/users/4 also has the xss vuln when escaped with {!! !!}

The issue lies in the Vue part, because when I change the <div id=app> to <div id=no-app> the data is not escaped, preventing the XSS alert box to pop. When I changed this the comments section etc that rely on Vue stopped working.

ERROR: for laravelblog_mysql_1 Cannot create container for service mysql: invalid bind mount spec "/home/laravel-blog/storage/tmp/db:/var/lib/mysql:cached": invalid mode: cached

After docker-compose run --rm --no-deps blog-server composer install

ERROR: for laravelblog_mysql_1 Cannot create container for service mysql: invalid bind mount spec "/home/laravel-blog/storage/tmp/db:/var/lib/mysql:cached": invalid mode: cached

Run on:

[root@localhost laravel-blog]# docker -v
Docker version 1.13.1, build 30c1ca9-unsupported

[root@localhost laravel-blog]# docker-compose -v
docker-compose version 1.17.1, build 6d101fb

Illuminate\Database\QueryException

When I run $ docker-compose run --rm blog-server php artisan migrate , the first step of the 'Before Starting' section I get the following error message:
Illuminate\Database\QueryException : SQLSTATE[HY000] [2002] No such file or directory (SQL: select * from information_schema.tables where table_schema = laravel-blog and table_name = migrations) at /application/vendor/laravel/framework/src/Illuminate/Database/Connection.php: 664

I'm using Valet.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.