Giter Club home page Giter Club logo

laravel-tricks's Introduction

Laravel-Tricks is now under the ownership of Tighten, and all development is taking place under a private repo until we can extract some of its code and make it public.

This is an archive of an old public version of the codebase the previous owners created and kept in sync with their private version.


Laravel Tricks is a website created by Stidges and Maksim Surguy as an unofficial repository of tips and tricks for web developers using the Laravel PHP framework.

To see what this is about check out http://www.laravel-tricks.com!

Table of contents

Purpose and Features

The purpose of this repository is to provide a source of a real website that's using the Laravel PHP Framework and implements good design patterns for its architecture.

The features of Laravel-Tricks are:

  • Multi User platform that enables registered users to post short excerpts of code and descriptions to go along with the code.
  • Sorting and search.
  • Categories and tags for each user submitted entry.
  • OAuth 2 Github Registration and Login using OAuth 2 client from PHP League.
  • Disqus integration for commenting.
  • Customized Bootstrap theme.
  • AJAX favoriting.
  • Gravatar integration.
  • Using jQuery FileAPI for avatar uploads and cropping.
  • Using Intervention Image to handle the server side of the avatar uploads.
  • Pinterest-inspired grid implemented with Masonry.
  • Presenter classes implemented with the Laravel Auto Presenter package.

Requirements

The Laravel-Tricks website requires a server with PHP 5.4+ that has the MCrypt extension installed.

The database engine that is used to store data for this application could be any of the engines supported by Laravel such as:

  • MySQL
  • Postgres
  • SQLite and
  • SQL Serve.

Quick Start and Installation

To get started and start making something of your own using this repository as a base: download this repository, create an empty database that this application will use, configure a few settings in the app/config folder and enjoy!

Configuration

  • Open up app/config/database.php and configure connection settings for your database.

  • Configure hostname in bootstrap/start.php file to match your machine's hostname:

    $env = $app->detectEnvironment(array(
    
        'local' => array('your-machine-name'), // Edit this line
    
    ));
    
  • If you want to use Github OAuth for login and registration, make sure to create a Github application first and provide its client ID and client secret to the config in app/config/social.php. Also make sure you're using http://<your-site.com>/login/github for Authorization callback URL

After this simple configuration you can populate the database by running a couple commands shown below.

Installation

CD into the directory of this project and run the following three commands:

  1. composer install
  2. php artisan migrate
  3. php artisan db:seed

This will install all Composer dependencies, create the database structure and populate the database with some sample data so that you could see this project in action.

Documentation

While the code of the application is heavily documented it helps to know how the code is structured and what standards it follows.

Project structure

To start, we have removed the app/models directory and created a custom namespace for the site. This namespace houses all of the application's domain classes.

After that, we have namespaced the app/Controller directory, so that whenever new controllers are created composer dump-autoload doesn't have to be called every time.

The domain classes can be found in the app/Tricks directory. This contains all the application's logic. The controllers merely call these classes to perform the application's tasks.

The app/Tricks directory is structured in the following manner:

  • Exceptions: Contains all the exceptions that are thrown from within the domain classes. All the exceptions (except for the GithubEmailNotVerifiedException) extend the Tricks\AbstractNotFoundException class. This makes it much easier to handle 404 errors. (The handling can be found in the app/start/global.php file).
  • Facades: Contains all the custom Facade classes that are used throughout the application.
  • Presenters: Contains all the Presenter classes which utilizes the Laravel Auto Presenter package. This provides a clean way to keep logic out of your views and encapsulate it all into one place.
  • Providers: Contains all the application's Service Provider classes, which register the custom components to the application's IoC container. This, among many other advantages, eases the process of injecting classes/implementations and allows the creation of Facades.
  • Repositories: Contains all the Repository classes. Repositories are used to abstract away the persistance layer interactions. This causes your classes to be less tightly coupled to an ORM like Eloquent. All the repositories implement an interface found in the root of the Repositories directory, which makes it easier to switch implementations.
  • Services: This directory is split into multiple sub-directories:
    • Forms: Contains the Form classes, which are used to validate the user input upon form submission.
    • Navigation: Contains the navigation Builder class, which is used to build the site's navigation from a configuration file. The configuration file can be found under app/config/navigation.php.
    • Social: Contains the social integration classes for Github and Disqus. The Github class is used for the Github login and registration process. The Disqus class is used to get the comment count for the tricks.
    • Upload: Contains the ImageUploadService class. This class handles the uploading and resizing of an avatar.

Standards

The Laravel-Tricks application is PSR-2 compliant (and PSR-0 and PSR-1, which PSR-2 extends). PSR-2 is a coding standard by PHP-FIG which aims to unify the way PHP code gets written, so that everyone collaborating on a project will adhere to the same standards. This makes the code easier to read and understand.

Contributing

Contributions to this repository are more than welcome although not all suggestions will be accepted and merged with the live site.

Community

Keep track of development and Laravel-Tricks news.

Authors

Stidges

Maksim Surguy

Copyright and license

Code released under the MIT license.

laravel-tricks's People

Contributors

assertchris avatar cborgia avatar cojocaru avatar jash-ash avatar jbruni avatar kolyaio avatar mattstauffer avatar mizix avatar msurguy avatar neeraj1005 avatar remo avatar stidges avatar thomashenley avatar yhbyun 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

laravel-tricks's Issues

Eloquent methods in controllers

Per twitter discussion with @msurguy, these should be extracted into a repository:

UserTricksController lines 150-152:

$trick->tags()->detach();
$trick->categories()->detach();
$trick->delete();

TricksController line 80:

$voted = $trick->votes()->whereUserId($user->id)->first();

TricksController line 84:

$user = $trick->votes()->attach($user->id, [
    'created_at' => new \DateTime,
    'updated_at' => new \DateTime
]);

TricksController line 91:

$trick->votes()->detach($voted->id);

TricksController line 95:

$trick->save();

Feature: Google Login

Right now, it's a bit confusing, when you want to comment, you can log in using your google account, but not using your github account while you can only use github to log in to create a trick.

If we'd support google in both places, one would at least not have to use two different accounts on one site...?

Fatal Error Exception after install

followed the instructions to install locally on windows and the following exception is provided:-
...
Symfony \ Component \ Debug \ Exception \ FatalErrorException
Class Tricks\User contains 3 abstract methods and must therefore be declared abstract or implement the remaining methods (Illuminate\Auth\UserInterface::getRememberToken, Illuminate\Auth\UserInterface::setRememberToken, Illuminate\Auth\UserInterface::getRememberTokenName)
...

Move like button

It took me a bit of time to find the like button, it would be nice if it was more visible within the post.

Bug : total tricks count in user public profile view

I think that total tricks count shows wrong number in user public profile view. At line 24 in app views/user/public.blade.php file,

<tr>
    <th>Total tricks:</th>
    <td>{{ count($tricks) }}</td>
</tr>

It shows not total tricks number but tricks count in one page. I think it should be changed as follows.

<tr>
    <th>Total tricks:</th>
    <td>{{ $tricks->getTotal() }}</td>
</tr>

The similar bug appears in the next Last trick. It shows last posting date in one page, but I have no good idea to fix this bug.

<tr>
    <th width="140">Last trick:</th>
    <td>{{ $user->lastActivity($tricks) }}</t
</tr>

I hope this will help your coding.

New Form Fields and Database Table Columns

Hello Guys,

I created new form fields in the settings area (settings.blade.php).

I also added the new data to the UsersTableSeeder.php like so:
[
'username' => 'kwame',
'email' => '[email protected]',
'password' => Hash::make('password'),
'city' => 'London',
'country' => 'UK',
'descriptiom' => 'I am a PHP developer based in London',
'is_admin' => '1'
]

What else do I have to do to make this work properly (and create columns) so that I can seed the new data into it?

What am I missing? I hope someone can help me solve this.

Error while migrating

I got the source and was trying to boot up the app. While trying to migrate, I got the following error:

PHP Warning: require(/home/myuser/Development/php/laravel-tricks/bootstrap/../vendor/autoload.php): failed to open stream: No such file or directory in /home/myuser/Development/php/laravel-tricks/bootstrap/autoload.php on line 17
PHP Fatal error: require(): Failed opening required '/home/myuser/Development/php/laravel-tricks/bootstrap/../vendor/autoload.php' (include_path='.:/usr/share/php:/usr/share/pear') in /home/myuser/Development/php/laravel-tricks/bootstrap/autoload.php on line 17

Am I missing a file?

Why two lines instead of one?

1 - original

    public function findAllForUser(User $user, $perPage = 9)
    {
        $tricks = $user->tricks()->orderBy('created_at', 'DESC')->paginate($perPage);

        return $tricks;
    }

2 - edited

    public function findAllForUser(User $user, $perPage = 9)
    {
        return $user->tricks()->orderBy('created_at', 'DESC')->paginate($perPage);
    }

edit avatar image error

While editing avatar image from profile, it is responding with Server Internal Error. As per my debug analysis, i found that particular image file is not being sent, or it is giving error as file not found exception. Can any one help me on that.

php artisan migrate and db:seed exception no such file or directory??

─[yuchao@localhost] - [~/htdocs/tricks] - [2014-09-25 04:08:49]
└─[210] <> php artisan migrate

[PDOException]
SQLSTATE[HY000] [2002] No such file or directory

migrate [--bench[="..."]] [--database[="..."]] [--path[="..."]] [--package[="..."]] [--pretend] [--seed]

┌─[yuchao@localhost] - [~/htdocs/tricks] - [2014-09-25 04:08:54]
└─[210] <> php artisan migrate --path="./app/database/migrations/"

[PDOException]
SQLSTATE[HY000] [2002] No such file or directory

migrate [--bench[="..."]] [--database[="..."]] [--path[="..."]] [--package[="..."]] [--pretend] [--seed]

please send me the sql file about the tricks ,thanks ,my email is: yuchao86 at gmail dot com.

Having problems installing on windows

Hi,

I've been trying to install this using wamp and haven't been having any luck. I'm redirected to site unavailable. Any help would be greatly appreciated!

bad asset file names

I was always thinking I'm doing something wrong but now that I'm working on it again and still don't understand it, I really wonder what I'm missing.

There a file called [email protected] in this directory. https://github.com/CodepadME/laravel-tricks/tree/master/public/img. However, when I look at the code https://github.com/CodepadME/laravel-tricks/blob/master/app/views/partials/navigation.blade.php#L12 I only see a reference to [email protected].

I renamed a bunch of files when I first deployed it to my site, but I'd like to be able to pull changes from the official repository which isn't possible anymore due to a number of differences.

Whoops, looks like something went wrong.

The installation was successful. When you open the site - this error: Whoops, looks like something went wrong.

Predis\Connection\ConnectionException
…/­vendor/­predis/­predis/­lib/­Predis/­Connection/­AbstractConnection.php141

Predis \ Connection \ ConnectionException
Connection refused [tcp://127.0.0.1:6379]

  • Helper method to handle connection errors.
    *
    • @param string $message Error message.
    • @param int $code Error code.
      */
      protected function onConnectionError($message, $code = null)
      {
      CommunicationException::handle(new ConnectionException($this, "$message [{$this->parameters->scheme}://{$this->getIdentifier()}]", $code));
      }

Installation problems using "laravel/framework": "4.1.*"

I'm trying to install the app project files using composer and it seems that for some reason Laravel version 4.1 is no longer accessible from the composer installation. Its possible to confirm this? Or maybe I'm doing something wrong. In the mean time, I change composer's Laravel requirement to 4.2 and the installation runs smoothly.

Test

Could you upload also your tests?

What is 'access_token_secret' good for?

As far as I can see, nothing has changed in this area, but on my new box, I can't get github login working because I get this error:

Field 'access_token_secret' doesn't have a default value

This field is never set and isn't nullable either. What's the purpose of this field? I'm sure I'm missing something, seems to happen quite often to me these days 🚶

[Proposal] Add a List View

Instead of looking at all the items through out the page i'd rather just see a list. Would be awesome if you could implement such a feature, so that user can decide whether he wants the items as a grid or listed as a list.

Feature: Make the Post View right meta box "sticky"

I'd like to see the meta box on the post page as a "sticky" box, meaning it will stick to the top of the page when you scroll. This will help keep the information in view.

May help solve this problem as well: #5

Question: use Illuminate\Support\Facade\Str;

Hi again,

I have one more issue, don't know if its a bug.
After a fresh install on the project, I tried to save as admin a new tag or category, and I get : Symfony \ Component \ Debug \ Exception \ FatalErrorException
Class 'Illuminate\Support\Facade\Str' not found

I fixed it by changing in the Tagrepository.php from: use Illuminate\Support\Facade\Str; -> use Illuminate\Support\Str;

Not yet very advanced in all this Facades stuff but would be interesting to know why this error happened and if others also get it.

Thank you.

Comments count 0 in Card View

Could you please share the code regarding getting the count from disqus for each trick in card view. Currently it is hardcoded as 0.

Thanks in advance

Help: Github login fail

Hi,

I just try to run a local copy of laravel-tricks on my laptop.
Everything looks fine (ex. register, login, create trick), but only fail on login with github.

When login with github, the page will redirect to '/login/github' with code & state get params.
And show "Argument 1 passed to Tricks\Repositories\Eloquent\UserRepository::createFromGithubData() must be an instance of League\OAuth2\Client\Provider\User, instance of League\OAuth2\Client\Entity\User given, called in .../app/Tricks/Services/Social/Github.php on line 95 and defined"
(The screenshot has attached)

I had setup 'clientId', 'clientSecret' and 'user_agent' correctly in app/config/social.php, but can't find out how this error happen.
Any suggestions would be greatly appreciated! Thanks!

screen shot 2014-06-18 at 10 32 57 pm

Question: public resources

Hi authors,

Sorry, could be a dummy question but still I don't get it. Why are the names of resources like URL::asset('css/laratricks.min.4.css') , include '.4' in the name. Should I rename them manually, is there some automatic way like a command.

Thx in advance. And thx for sharing.

Class 'User' not found in admin/users

Getting /admin/users route throws a FatalErrorException.

Route: /admin/users

FatalErrorException
Class 'User' not found

Template: app/views/admin/users/list.blade.php

<h1>Showing all users ({{User::count()}})</h1>

Namespacing the class does work:

<h1>Showing all users ({{Tricks\User::count()}})</h1>

Thanks!

GitHub.php: Invalid argument supplied for foreach()

screenshot 2014-07-14 17 43 26

Experiencing Invalid argument supplied for foreach() when I attempt to register with GitHub. Here is the function:

/**
 * Get the primary, verified email address from the Github data.
 *
 * @param  mixed $emails
 * @return mixed
 */
protected function getPrimaryEmail($emails)
{
    foreach ($emails as $email) {
        if (! $email->primary) {
            continue;
        }

        if ($email->verified) {
            return $email->email;
        }

        throw new GithubEmailNotVerifiedException;
    }

    return null;
}

Refactor storeViewedTrick/getViewedTricks

These methods (and similarly named ones) are present in both Tricks\Events\ViewTrickHandler and Tricks\Filters\ViewThrottleFilter. Perhaps a trait or repository should be used to eliminate the repetition.

Login github fail

I have installed laravel tricks, league/oauth2-github, created github app with id and secret key. After login successfully on github, it callback to my website and this error is appear. What's my problem? Thanks for help!
laravel

User types

Hi,

I saw in config such option:

// available user permission types that are matched by user_type column in the users table
'user_types' => array(
    'admin'     => 100,
    'reviewer'  => 20,
    'user'      => 10
),

but no management for this, are there any plans for implementing this?

Unique category slug

Hi,

When I try to save a category with the same name , because the slug has to be unique I get an Illuminate \ Database \ QueryException .

SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'aaa' for key 'categories_slug_unique' (SQL: insert into categories (name, slug, description, order, updated_at, created_at) values (aaa, aaa, aaaa, 4, 2014-03-09 19:57:16, 2014-03-09 19:57:16))

I will try to fix this in one fork soon, so if it will not be fixed meanwhile will propose a pull request, thx.

Post title change updates URL slug

I think it would be better if the URL slug did not update with the title of the post. If a user posts a trick, then later on changes the title, the anyone linked to that page will break.

I propose one of a few options:

  1. Disable updating or URL slug. Once it's created, it's set (This could be seen as a bad feature though)
  2. Use a unique ID of some kind instead (I think this was mentioned elsewhere...)
  3. Somehow keep track of the changes and have a redirect to the new URL (This could be overkill)

Thoughts?

Model relationship table question.

Hi ,

I have one question that is not only specific to this project but you also used it, so maybe you can shortly help me or point to some resource.
I can figure out how the pivot table tag_trick is managing the many to many relationship.
I found in Trick model the : protected $with = [ 'tags', 'categories', 'user' ]; (which is related to eager loading), and the standard belongsToMany methods, but I am wondering is this enough to create a new pivot table? e.g. subcategories, is it enough to set the belong to relationship, and laravel itself is managing it?

In short how the application knows about pivot table tag_trick?

thanks in advance, and if its off topic you can close it.

[Proposal] To port the application to Laravel 5.2.10

The application is using the older version of the Laravel framework. The idea is to study the application completely and rewrite most of the part to leverage the latest Laravel framework as this stands as a good well structured application where many developers study and learn good practises from. Moreover being a big fan of laravel-tricks.com and learning a lot from that I think it would be great to update the codebase to the newer framework version.

Move text into "lang" directory

What do you guys think about using the "lang" directory? That would make it easier to translate and white-label this project.

Question: function in repository but not in interface

So I'm still learning about interfaces and using the repository pattern in Laravel. My question is whether the controller should be calling a method on the repository that is not present on that repository's interface. For example, in the UserTricksController, we call getEditForm on the Trick repository (line 122):

$form  = $this->trick->getEditForm($trick->id);

The getEditForm method is not present on the TrickRepositoryInterface, however, but it is on the TrickRepository.

Feature: Make intro text Markdown

I would like to see the intro text for a post to allow Markdown. When I recently posted something, It took my paragraphs and smashed them all together into one big paragraph. At the very least, can we get some nl2br() going on?

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.